Efficiently combine Paging and Filtering

1 Answer 209 Views
Grid
James
Top achievements
Rank 1
James asked on 30 Aug 2021, 11:25 PM

For filtering we are using the kendo data query "process" library.  The issue is that when you combine this with paging, there are issues with determining the total number of items since "process" returns an array only of your page size. 

So I essentially have to run "process" twice:

1.  So I can get the filtered and paged data

2.  Again with just the filter parameters so I can get how many total items are in the set after filters have been applied

 

For example:


loadItems() { const myData: any = []; //Some data in here let gs: State = { skip: 0, take: 10, filter: { //Some filter data } as CompositeFilterDescriptor };

//THis will filter my data, then return the paged slice of it let gd: GridDataResult = process(myData, gs);

//This will run just the filter so I can get the total items gd.total = process(myData, {filter: gs.filter} as State).data.length; }


Is there a better way to get the total number of filtered items when I am also using paging instead of having to run "process" twice?  I have thought about extending the "process" so I can add an extra field on it with total entries but not sure how to get started. 

Any assistance would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Accepted
Svet
Telerik team
answered on 02 Sep 2021, 08:22 AM

Hi James,

Thank you for the provided details.

In general the process() method accepts one parameter of type array and a second one of type State and returns an object of type DataResult. The State parameter can contain info for the paging and for the current Grid filters. The info for the paging should be passed with the skip and take properties, while the info for the applied filters should be passed in the filter property. The returned value by the function is of type DataResult which provides an array of the processed data items in the data property (that is the current data that will be displayed by the Grid) and the total number of items (these are he total number of records that are available not just the number of the items in the data property) in the total property.

To sum up, running the process() method once can process the passed data as per the passed paging and filtering details and returns the processed data and the total number of items that were initially passed for processing to the function.

I hope this helps.

Regards,
Svet
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Svet
Telerik team
Share this question
or