This is a migrated thread and some comments may be shown as answers.

Custom Grid paging only shows 1st page unless all the data is returned for ToDataSourceResult

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
freeTheCode
Top achievements
Rank 1
freeTheCode asked on 02 Dec 2018, 05:05 PM

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. 

 


1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 04 Dec 2018, 01:48 PM
Hi,

Although we strongly recommend using a data layer and follow the single responsibility principle, in order to simplify the code snippets in our docs articles we directly use the db context in the action methods.

I have examined the provided snippet and I did not notice anything that might cause an issue. In case the orderSearcher.GetOrders(model) method returns the correct page the grid should display the date as expected.

Could you please make sure that the GetOrders method returns the correct page after the first navigation?

Having said that, sharing a demo that clearly replicates the issue would definitely help us fully understand the case and we will be able to provide further assistance to the best of our knowledge.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
freeTheCode
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or