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 615 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.
Surya
Top achievements
Rank 1
commented on 27 Jan 2022, 08:17 PM

I'm facing the same issue. My grid has to perform server side paging/filter and sort. The grid currently fetched 20 of 200 records with total record count on Page 1. when I click on pagination icon to load Page 2, my controller method gets the next 20 records but my grid loads empty with total record count showing on pagination area of the grid.
Anton Mironov
Telerik team
commented on 31 Jan 2022, 02:36 PM

Hi Surya,

Thank you for the details provided.

In order to achieve the desired behavior, I would recommend trying the approach from the following demo:

The main part of the implementation above is the "AjaxCustomBindingExtensions" method in the "GridController" file. Try using the Take and Skip methods as represented in the demo.

Give a try to the approach above and if the issue persists, send me a runnable sample of your application and I will try my best to fix it locally.

Looking forward to hearing back from you.

Kind Regards,
Anton Mironov

 

 

Tags
Grid
Asked by
freeTheCode
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or