Kendo grid mvc - 通过javaScript函数传递网格行

时间:2016-10-19 12:47:33

标签: javascript jquery asp.net-mvc kendo-ui kendo-grid

我使用带有复选框客户端模板的kendo网格,我想将该行传递给函数。

<div>

    @(Html.Kendo().Grid(Model).Name("EvaluationFormGrid").DataSource(dataSource => dataSource
          .Ajax()
          .Model(model =>
          {
              model.Id(m => m.EventEvaluationFormId);
              model.Field(m => m.EventEvaluationFormId).Editable(false);
          })
          .Destroy(delete => delete.Action("DeleteEvaluationForm", "EvaluationFormsManagement"))
          .PageSize(60)
          .ServerOperation(false)
          ).Columns(c =>
          {
              c.Bound(m => m.EvaluationFormTitle).Width(150).Title("Evaluation Form Title");
              c.Bound(m => m.EvaluationFormLink).Width(300).Title("Evaluation Form Link");
              c.Bound(m => m.ModifiedUserName).Title("Mod. by").Width(80);
              c.Bound(m => m.ModifiedDateUtc).Title("Mod. date").Width(80);
              c.Bound(m => m.IsDisplayedInApp).Title("Is displayed in app").Width(80)
                 .ClientTemplate("<input type='checkbox' #= IsDisplayedInApp ? checked='checked' :'' # value='#=IsDisplayedInApp#' onClick='onChange(#=IsDisplayedInApp#)'/>");
              c.Bound(m => m.EventEvaluationFormId).Title(string.Empty).Width(80)
                  .ClientTemplate("<a class='table-entry-control edit-entry-control' href='" + Url.Action("ManageEvaluationForm", "EvaluationFormsManagement",
                      new { area = "Admin" }) + "/#= EventEvaluationFormId #'" + "><span class=\"k-icon k-edit\"></span>Edit</a><br />")
                  .Sortable(false);
              c.Command(commands =>
              {
                  commands.Destroy();

              }).Title("").Width(80);

          })
          .Events(events => events.Change("onChange"))
          .Editable(e => e.DisplayDeleteConfirmation(true)).Deferred().DataSource(datasource =>
              datasource
                  .Ajax()
                  .ServerOperation(false)).Deferred(true))


    <script>
        function onChange(arg) {
            alert(arg);
            var selected = $.map(this.select(), function (item) {
                return $(item).text();
            });

            kendoConsole.log("Selected: " + selected.length + " item(s), [" + selected.join(", ") + "]");
        }
    </script>

</div>

有了这一行,我想传递整行,现在我只传入一个布尔值:

c.Bound(m => m.IsDisplayedInApp).Title("Is displayed in app").Width(80)
                     .ClientTemplate("<input type='checkbox' #= IsDisplayedInApp ? checked='checked' :'' # value='#=IsDisplayedInApp#' onClick='onChange(#=IsDisplayedInApp#)'/>");

有谁知道如何在这里传递行:

onClick='onChange(#=IsDisplayedInApp#)

由于

1 个答案:

答案 0 :(得分:0)

试试这个:

function onClick(chk) {
   var grid = $('[name="EvaluationFormGrid"]').data("kendoGrid");

   // Get the row
   grid.dataItem($(chk).closest("tr"));
};

我不习惯Kendo MVC因此我不知道.Name()生成了什么,但是在函数的第一行,您必须将网格widgtet实例添加到grid var