I have a MVC Kendo Grid as follows. It is working fine with default paging.
Now, I want to do custom paging. In the controller action we need to know the current page index. Also it should set the “total” count for the grid. [The actual data source will have only 2 records at a time even if there are 100 records in the database. So the grid must know the total number of records in database using “total” attribute.]
The query should return only 2 records from the database at a time.
How can we do this custom server paging using the MVC wrapper for Kendo Grid?
@using (Html.BeginForm())
{
@(Html.Kendo().Grid<KendoUIMvcSample.Models.Sample>()
.Name("ssgrid222")
.Columns(columns => {
columns.Bound(p => p.SampleDescription).Filterable(false).Width(100);
columns.Bound(p => p.SampleCode).Filterable(false).Width(100);
columns.Bound(p => p.SampleItems).Filterable(false).Width(100);
})
.AutoBind(false)
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(2)
.Read(read => read.Action("Orders_Read", "Sample")
)
)
)
}
Controller
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
{
int currentPageNumber = request.Page;
return Json(GetOrders().ToDataSourceResult(request));
}