That's right, you need to pass the Total field in your answer.
Your view might look like this:
@(Html.Kendo().Grid<YourViewModel>() .Name("grid") .DataSource(dataSource => dataSource .Ajax() .PageSize(20) .ServerOperation(true) .Read(read => read.Action("Data_Read", "YourController", new {Id=Model.CurrentId})) ) .Columns(c => { c.Bound(x => x.Name); c.Bound(x => x.CreatedTime); }) .Pageable() .Sortable() )
Your action code is as below:
public ActionResult Data_Read([DataSourceRequest]DataSourceRequest request, int Id) { int total = yourQuery.GetTotal(Id); var returnViewModel = yourQuery.GetViewModels(Id, request.Page, request.PageSize); return Json(new { Data = returnViewModel, Total=total }); }
Look at the request and response in Fiddler, you will see how the magic happens: Request: sort = SessionId-asc & page = 7 & pageSize = 20 & group = & filter =
This is the DataSourceRequest format that the grid passes to the controller; it already contains the parameters needed for the paging call.
Review the response from the action and you will see that there is a data field containing all the records. The Total field is the total amount for all the records that are needed to pager the Kendo grid.
Jim yu
source share