我不知道您实际上是如何触发 NextPage、PreviousPage 操作的,但是...
您可以使用 MVC 自定义数据源配置来提供对更多选项(如 Schema 配置)的访问。
http://docs.telerik.com/aspnet-mvc/getting-started/custom-datasource
Schema 配置允许您添加一个 Parse 函数,该函数可以采用您的自定义结果格式:
{ items: [. . . ], nextPage: 'J23jeg9e93', previousPage: 'oqow0r93285' }
并提取项目(给网格)和下一个页面,上一个页面值(供您存储以传递给下一个读取请求)。
例如:
示例网格:
@(Html.Kendo().Grid<TelerikMvcApp4.Models.GridViewModel>()
.Name("grid")
.DataSource(ds => ds
.Custom()
.Batch(true)
.Schema(schema => schema
.Parse(@<text>parseData</text>)
)
.Transport(transport => transport
.Read(read => read.Action("Grid_Read", "Home").Type(HttpVerbs.Post).Data("readData"))
)
.PageSize(1)
.ServerPaging(true)
)
.Pageable()
)
示例 parseData 和 readData javascript:
<script>
var nextPage,
previousPage;
function readData() {
// Return the "extra" data that should be posted with each grid read request, which is the nextPage/previousPage we were given in the previous request respsonse.
return {
nextPage: nextPage,
previousPage: previousPage
};
}
function parseData(data) {
// Parse the response from the server as it isn't in the typical format expected by the grid.
// Extract your nextPage/previousPage, store it somewhere so they can be added to the next grid request.
nextPage = data.nextPage;
previousPage = data.previousPage;
// Return the actual data that should be displayed in the grid.
return data.items;
}
</script>
示例网格读取操作:
[HttpPost]
public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request, string nextPage, string previousPage)
{
// "Fetch" the data, presumably doing something with nextPage and previousPage...
var items = new List<GridViewModel>()
{
new GridViewModel() { name = "bob", age = 23},
new GridViewModel() { name = "jim", age = 43},
};
// Determine what the new nextPage, previousPage should be...
var newNextPage = "J23jeg9e93";
var newPreviousPage = "oqow0r93285";
return Json(new
{
items = items,
nextPage = newNextPage,
previousPage = newPreviousPage
});
}
这不是一个完整、强大的解决方案,但我认为它可以变得可行,并且至少会为您指明一个可能的方向。