繁体   English   中英

从MVC Controller中的Telerik Kendo Grid获取检查的行

[英]Getting checked rows from Telerik Kendo Grid in MVC Controller

我有一个带有选中列的Telerik Kendo网格:

@(Html.Kendo().Grid<RunSummary>()
          .Name("CheckedPatients")
          .ToolBar(toolBar => 
                    toolBar.Custom()
                        .Text("Export To PDF")
                        .HtmlAttributes(new { id = "export" })
                        .Url(Url.Action("Export", "PatientReport", new { page = 1, pageSize = "~", filter = "~", sort = "~" })))

          .DataSource(datasource => datasource
                .Ajax().PageSize(25)        
                .Sort(sort => sort.Add("UniqueId").Ascending())                        
                .Read(read => read.Action("GetRunSummaries", "PatientReport")))
          .Columns(columns =>
              {

                  columns.Bound(c => c.UniqueId).Title(ELSORegistry.Resources.Views.Home.HomeStrings.UniqueId)
                        .ClientTemplate("<input type='checkbox' unlock='true' class='primaryBox' id='#= UniqueId #' />");
                  columns.Bound(c => c.RunNo).Title(SharedStrings.Run);
                  columns.Bound(c => c.Birthdate).Title(SharedStrings.Birthdate).Format("{0:g}").Filterable(true);

                  //columns.Bound(c => c.Age).Title(SharedStrings.Age).ClientTemplate("#= formatAge(Age)#");
                  columns.Bound(c => c.TimeOn).Title(PatientStrings.TimeOn)
                      .Format("{0:g}")
                      .Filterable(true);
                  columns.Bound(c => c.TimeOff).Title(PatientStrings.TimeOff)
                      .Format("{0:g}")
                      .Filterable(true);
                  columns.Bound(c => c.DischargedAlive).Title(SharedStrings.Age).Filterable(true);
              }
          )
          .Pageable(p => p.PageSizes(new[] {10, 25, 50, 100}))
          .Sortable()
          .Filterable( )
          .Events( e => e.FilterMenuInit("FilterMenuFunc") ) // apply x [closing box] on pop up filter box
          )

我必须在控制器的操作中获取检查的行。 请帮忙怎么做? 先感谢您

我从您的问题中了解到的是,您正在尝试选中控制器中的复选框。 为此,您必须具有一个指标,并在控制器中设置其值,然后通过模型并将其与复选框所在的列绑定。 现在用这个

.ClientTemplate(“ <输入类型='复选框'#=指示器?checked ='选中':''#class ='chkbx'id ='#= UniqueId#'/>”)

这里的指标是您将要与列绑定的指标。 如果已设置,则将选中复选框,否则未选中。

我终于找到了解决方案。 首先,将所有选中的框收集到一个数组中:

$(document).on('change', '.primaryBox:checkbox', function (e) {
        var isChecked = $(this).is(':checked');
        if (isChecked) {
            checkedArray.push($(this).val());
        } else {
            checkedArray.remove($(this).val());

        }
    });

然后,使用Ajax将数组发送到控制器:

$.ajax({
            type: "POST",
            url: "/PatientReport/ExportToPDFStoredProcedures",
            dataType: "json",
            traditional: true,
            data: { uniqueIds: checkedArray },
            success: function (data) {
                if (data.success) {
                     //do something
                                   } 
           else {
                    //do something else;
                }
...and finally in the controller make an action that has uniqueIds as argument:
public ActionResult ExportToPDF(List<String> uniqueIds)
        {  
//do something with UniqueIds
}
                },

这将适用于网格的当前页面。

            var checkedItems= [];
            $(".cbGridRow").each(function () {
                var cbRow = $(this);
                if (cbRow.is(':checked'))
                    checkedItems.push(this.id.substring(2));
            });

但是,如果网格设置为“可分页”,则必须在两次页面转换之间保存和加载选择。 最简单的方法是绑定到页面之前和之后的功能,并维护一组唯一的ID。

或绑定到更改事件,然后将每个选中的项目读入一个持久数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM