- Home
- Forum
- Angular - EJ 2
- Paging issues when doing server side paging with custom filter
Paging issues when doing server side paging with custom filter
Hi,
I'm using syncfusion ej2 v26.1.35. I'm using a grid to diplay my customers with paging enabled and the following initial pageSettings:
pageSettings: PageSettingsModel = {
pageSizes: [5, 10],
pageSize: 5,
pageCount: 3
};
The dataSource property of the Grid is binded to a variable that is initialized in the ngOnInit of my component for the first time. Then data is reloaded from server at each dataStateChange event trigger. From the event arguments I retrieve the skip / take data needed to do the server side paging. My event implementation looks like:
onGridDataStateChange(args: DataStateChangeEventArgs) {
this.lastStateChangeArgs = args;
getData(args.skip, args.take); //sets a new dataSource
}
The server returns an object of type
myDataSource = { result: [], count: number } where result is the list of items for the current page and count is the total count of objects, so that the Grid can calculate the number of pages etc...
I also have a custom filter outside the grid, for the sake of simplicity lets say it is just a simple textbox to filter my Customers by their Name when I click on my "Filter" button. The event is implemented like that:
filterClick() {
getData(this.lastStateChangeArgs.skip, this.lastStateChangeArgs.take);//sets a new dataSource
}My issue:
- initially lets say without any filter the ngOnInit data is 5 customers for a total count of 9. Everything runs fine
- then I set a filter for the name "John" and click the "Filter" button. The data source of the Grid is now updated to 3 customers for a total of 3 and it runs fine
- but when I reset my filter and call my server again to update the dataSource with the same initial dataSource, something weird happens: dataStateChange event is triggered with a "paging" event where take is equal to the count of the dataSource (9), and same for the pageSize (9). When I did not at all change the pagesize or anything. Moreover, as I say inside this event I call again my server to retrieve the data, wich triggers another dataStateChange event, wich updates the datasource, wich triggers the event (only 2 times...). So here my server is called 3 times: first time with a correct take of 5, then 2 more times with a wrong take/pageSize of 9. At the end, even if the grid displays a pageSize of 5, it shows 9 elements and everythin is messed up.
- from now on, each time I try to filter my data, the take/pageSize is set to the "count" property of the dataSource
Can you explain to me why the dataStateChange event is triggered somewhat randomly when I update the grid's dataSource, and why it's doing so with a wrong take/pageSize ? Is there a way to prevent this very weird behavior ?
Thank You,
Mehdi
dataStateChange event is triggered multiple times—with an unexpected pageSize equal to the total count—after resetting a custom filter.filterClick() method, you're directly replacing the Grid’s dataSource instead of using the Grid's built-in column filtering mechanism. When you do this, the Grid internally assumes that the data has changed and may adjust its paging behavior accordingly.dataSource is set without properly maintaining pageSettings, the Grid attempts to recalculate it based on the new data length.dataSource. This ensures the Grid handles the filter action properly and keeps paging intact.dataStateChange. So it is important to:- Maintain a consistent
stateobject - Update the
queryorwhereclauses accordingly
dataStateChange is triggered only once per action.Code Example: <input type="text" #filterInput /> <button (click)="onClick(filterInput.value)">Filter</button> <button (click)="clearFilter(filterInput)">Reset</button> onClick(value: string): void { this.grid.filterByColumn('CustomerID', 'contains', value); } clearFilter(input: HTMLInputElement): void { input.value = ''; // Clear the input this.grid.clearFiltering(); } |
- Grid Configuration : Can you please share the complete Grid rendering code?
- Custom Binding and Filtering Logic : How have you implemented the
dataStateChangemethod? Please sharehow you manage and store the state object within this method. What logic is executed in your externalfilterClick()and reset functions? How do you update the Grid’sdataSourcewithin these functions?
- Service and Server-side Logic: Can you share the code for your data service, especially the part where server-side operations are handled?
- Reproducible Sample : Can you provide a runnable sample that reproduces the issue? Alternatively, are you able to replicate the issue using the sample we previously shared?
Regards,
Hi Sivaranjani , and thank you for your answer and sample,
First of all, yes you are right:
- I'm using custom databinding and you spotted the issue exactly
- I'm directly replacing the dataSource, that's because I dont want to use the builtin filter features
- type "ch" in the filter input
- click on the filter button
- you'll get 5 items total and paging is still fine on both versions
- type "c" in the filter input
- click on the filter button
- you'll get as expected more items total: 26
- the grid will display 6 pages of 5 elements
- only 5 éléments are displayed
- the grid will display only 1 page
- all 26 elements will be displayed, when the items per page is still 5
- the issue is reproduced here, the dataStateChange event has been triggered with a pageSize equal to 26
- Backup your old Syncfusion packages(node_modules>@syncfusion).
- Delete the package.lock.json file from your application.
- Remove the @syncfusion package folder from the node_modules directory.
- Use the latest version or “*” (which installs the latest packages) for all Syncfusion components in package.json file.
- Then install the NPM packages.
Package.json "dependencies": { "@syncfusion/ej2-angular-grids": "*", "@syncfusion/ej2-base": "*", "@syncfusion/ej2-data": "*", . . . . . . . . . } |
For further details, please refer to the documentation below:
- Version Compatibility : https://ej2.syncfusion.com/angular/documentation/upgrade/version-compatibility
- Upgrade NPM packages : https://ej2.syncfusion.com/angular/documentation/common/how-to/update-npm-package
Documentation Link : https://ej2.syncfusion.com/angular/documentation/grid/columns/columns#autofit-columns-with-empty-space
If you face issues with latest version or have further questions, please share details, and we’ll assist promptly.
Regards,
Sivaranjani R
- 3 Replies
- 2 Participants
-
DL DSI Licensing
- Jun 30, 2025 12:24 PM UTC
- Jul 3, 2025 12:21 PM UTC