【问题标题】:Kendo Grid with Server Side Paging and Grouping带有服务器端分页和分组的 Kendo Grid
【发布时间】:2013-11-23 19:25:28
【问题描述】:

我正在为 Kendo UI (2013.2.830) 使用 ASP.NET MVC4 和 MVC 包装器。 我的目标是让服务器端分页/排序/过滤/分组都与剑道网格一起工作。我可以让分页/排序/过滤正常工作......但需要一些关于如何处理分组的建议。这是我到目前为止从网格调用的操作的内容:

public ActionResult GetGridDataSource([DataSourceRequest] DataSourceRequest request)
{
    // get the data using the values from the request
    EntityCollection<CustomerEntity> customers;
    int totalItemCount;
    using (var proxy = new CustomerServiceProxy())
    {
        // NOTE: just an example... 
        // The service doesn't take in the kendo data types for sort/filters.
        // They are transformed to data types that the service does use.
        customers = proxy.FindCustomers(
            request.Filters,
            request.Sorts,
            request.Page,
            request.PageSize,
            out totalItemCount);
    }

    // build the datasource using the view model
    var dataSource = (from customer in customers
                      select new CustomerViewModel
                      {
                          CustomerName = customer.Name,
                          // etc
                      }).ToList();

    // this code returns the data for the requested page correctly
    var result = new DataSourceResult();
    result.Total = totalItemCount;
    result.Data = dataSource;
    return Json(result, JsonRequestBehavior.AllowGet);
}

如果我使用var result = dataSource.ToDataSourceResult(request);,那么除了分页之外一切正常(在第 1 页之后没有数据返回给客户端)。看来 ToDataSourceResult() 方法正在尝试从 dataSource 中提取第 2 页,即使 dataSource 已经代表第 2 页。

理想情况下,如果可以解决分页问题,​​我想使用 ToDataSourceResult()。 否则,我假设我需要在设置 result.Data 属性之前手动将分组应用到我的数据源,以便返回的 JSON 格式正确。有没有可用的剑道功能来做到这一点?如果我需要手动完成,有人可以提供一个示例,说明如何从请求中获取分组参数并将其应用于数据源,以便 JSON 正确吗?

谢谢!

【问题讨论】:

    标签: asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    请参阅 nugetgithub 上的 KendoGridBinderEx,它支持排序、过滤、分页、分组和聚合。

    【讨论】:

      【解决方案2】:

      试试这个:

      public virtual JsonResult GetGridDataSource([DataSourceRequest()] DataSourceRequest request)
          //Get data : var dataSource = ...
          int requestPage = request.Page;
          request.Page = 1;
          var result = dataSource.ToDataSourceResult(request);
          result.Total = sortpag.ItemCount;
          request.Page = requestPage;
          return Json(result);
      }
      

      【讨论】:

        【解决方案3】:

        here 提供的答案解释了一种服务器端方法,该方法非常适用于分页、过滤、排序和(最难以捉摸的)分组,所有这些都使用 Telerik 的 Kendo.Mvc .NET 库。

        请记住,我的回答使用了 JavaScript 声明的 Kendo DataSource,而不是使用 MVC 包装器,因为当我第一次编写解决方案时,它让我可以更好地控制所有 DataSource 选项。但是,您会发现更多关于 MVC 包装器方法 here,以及针对 WebApi 后端 here 使用 MVC 包装器。

        【讨论】:

          猜你喜欢
          • 2014-02-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-10
          • 2023-03-12
          • 2017-01-19
          相关资源
          最近更新 更多