Every example that has custom paging always fails to address the question. Every example has the controller receiving the DbContext for the ToDataSourceResult method to then do the paging which is not what is wanted.
Take a look at the example on this page: https://docs.telerik.com/aspnet-mvc/helpers/grid/binding/custom-binding#custom-ajax-binding
public
ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
{
//Get the data (code omitted).
IQueryable<Order> orders =
new
NorthwindEntities().Orders;
//Apply sorting (code omitted).
//Apply paging (code omitted).
//Initialize the DataSourceResult.
var result =
new
DataSourceResult()
{
Data = orders,
// Process data (paging and sorting applied)
Total = total
// Total number of records
};
}
The problem is when we don't pass our DbContext this far up.
I'm trying to do custompaging on the grid, my controller calls a middle layer which does the paging and filtering and returns an IList<OrderViewModels> with only the 20 items for the page. Except it doesn't work unless I return all 700,000 records. Then it magically pages and somehow this is supposed to be called serverside paging. It is only paging at the UI layer which is incredibly inefficient. Granted it is not doing it on the client, but it is still no good if it is at the UI layer as I'm having to return all records from the datalayer.
public
ActionResult GetFilteredOrders([DataSourceRequest] DataSourceRequest request, OrderSearchModel model)
{
var dataResults = orderSearcher.GetOrders(model);
// Users datalayer to returns the paged 20 items and total
var resultObject =
new
DataSourceResult()
{
Data = dataResults.OrderList,
// Process data (paging and sorting already applied)
Total = dataResults.DataTotal
// Total number of records
};
return
Json(result);
}
This only works on page 1 and nothing on any other page, even though I can see that dataResults has data.