如何在asp.net mvc的客户端Kendo UI网格中实现服务器端分页 [英] How to implement Server side paging in Client side Kendo UI grid in asp.net mvc
本文介绍了如何在asp.net mvc的客户端Kendo UI网格中实现服务器端分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我如何使用客户端 Kendo UI Grid 实现服务器端分页?
Can anyone tell me how can I implement server-side paging with client-side Kendo UI Grid?
推荐答案
更新:我们有 发布 一个开源的.NET 库,它使分页、排序和过滤变得更加容易.
UPDATE: We have released an open source .NET library which makes paging, sorting an filtering a lot easier.
一旦您将serverPaging
设置为true
,网格将发送当前的pageSize
和skip
.在服务器端,您应该使用提供的信息分页数据并将其与项目总数一起返回.这是一个代码片段:
The grid will send the current pageSize
and skip
once you set serverPaging
to true
. On the server side you should page your data using the provided info and return it together with the total number of items. Here is a code snippet:
public ActionResult Products(int pageSize, int skip)
{
using (var northwind = new NorthwindDataContext())
{
var products = northwind.Products;
// Get the total number of records - needed for paging
var total = products.Count();
// Page the data
var data = products.Skip(skip).Take(pageSize).ToList();
// Return as JSON - the Kendo Grid will use the response
return Json(new { total = total, data = data });
}
}
查看
$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "home/products",
dataType: "json",
type: "POST"
}
},
schema: {
data: "data", // records are returned in the "data" field of the response
total: "total" // total number of records is in the "total" field of the response
},
serverPaging: true // enable server paging
}
});
参考
使用 LINQ 进行分页
- Take() 和 Skip()
这篇关于如何在asp.net mvc的客户端Kendo UI网格中实现服务器端分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文