【发布时间】: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