The Kendo UI DataSource resets the current page to 1 during filtering by design and this behavior cannot be avoided. The idea is that a subset of the data items will be displayed, so the number of pages will be smaller and the current page may even not exist after the filtering.
If you require the filtering to work on the current page without making any requests to the web service, you can perform the filtering manually - retrieve all current data items, check the desired values and hide the table rows, which should not be displayed. Here are some relevant documentation links.
- get the Grid dataSource
- get all data items from the current page
- get the value of a given field of a given data item
- get the table row, which corresponds to a data item - use the data item's UID and construct a jQuery selector, having in mind that the UID is rendered as a data-uid
HTML attribute of the table row.
An alternative approach would be to iterate the table rows and retrieve each row's data item separately. This will spare you the need to look for the table row, based on the data item's UID.
- retrieve all table rows
- retrieve the data item from the iterated table row
There are a couple of things to keep in mind. First, you will either need to use custom filtering UI, instead of the Grid filtering UI, or use the native filtering UI, but cancel the rebind (server request) in the Grid's dataBinding
filterSettings = e.sender.dataSource.filter();
Cancelling the dataBinding event is not straightforward, because the same event is also fired when paging and sorting, so you need to figure out what the user has done. This can be achieved if you save the sorting, filtering and paging state of the dataSource in the dataBound
event and compare it with the state in the dataBinding event.
Also, since the Grid is not aware that it is "filtered", you will need to execute the above routine again after each paging if you want to persist the fake filtered state.
In general, you need to have the correct mindset that all the above techniques represent a hack, so if possible, consider using some other approach, which is supported out of the box.
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI