Hi! Is there a suggested way to keep the selected row of a grid after an operation of filtering, grouping or sorting?
I've searched for something similar and the suggestion that I've found is to keep the grid state on a cookie, but I think that's too much, I mean, for save only a row (maybe only an ID) use a cookie is too expensive.
Thank you,
Mattia
6 Answers, 1 is accepted
Thank you for contacting us.
For preserving the selected state after filtering, grouping, etc., operations, you need to handle the change event of the grid and keep an array with the selected items. Then, after the operations you could handle the dataBound event of the grid and see if the selected items are present in the current page (by comparing ID values or some other identifier). Once you find the existing items you can use the select method to select those rows.
In the following dojo example you can see the above in action:
- http://dojo.telerik.com/oWUcI working : http://dojo.telerik.com/InAfA
Hope this helps.
Regards,
Konstantin Dikov
Telerik
There was some issue with the previous example, so in the link below you can find the modified version:
Please let me know if you find some issues with the new version.
Regards,
Konstantin Dikov
Telerik
Hi Konstantin,
I have implemented your solution, works great, for the first grid.
I work with multiple grids ( with different ID's ), and I need to insert somehow the Id of the grid, in this line :e.sender.select(itemsToSelect)
if I try the :e.sender.select('#'+gridId+ itemsToSelect) I get the error:
Syntax error, unrecognized expression: #mygrid[object HTMLTableRowElement],[object HTMLTableRowElement]
if I work only with numbers, works good for all the grids:
:e.sender.select('#'+gridId+' tr:eq(' + some-number + ')');
Any help will be appreciated.
Thank you!
If you have multiple grid on your page, the best approach for handling the requirement would be to take the ID of the grid and change the _selectedOrders from the dojo example to be a two dimensional array [gridID][selectedDataItem].
Hope this helps.
Regards,
Konstantin Dikov
Telerik
Thank you Konstantin.
Solved my problem.