This is a migrated thread and some comments may be shown as answers.

Keep selected row after filtering/sorting/grouping

6 Answers 743 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattia
Top achievements
Rank 1
Mattia asked on 07 Sep 2015, 09:30 AM

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

Sort by
0
Konstantin Dikov
Telerik team
answered on 08 Sep 2015, 02:39 PM
Hi Mattia,

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:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Mattia
Top achievements
Rank 1
answered on 08 Sep 2015, 02:50 PM
Thank you Konstantin, that seems to work perfectly!
0
Konstantin Dikov
Telerik team
answered on 08 Sep 2015, 03:01 PM
Hello again Mattia,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Anca
Top achievements
Rank 1
answered on 17 Sep 2015, 07:24 AM

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!

 

 

0
Konstantin Dikov
Telerik team
answered on 22 Sep 2015, 05:45 AM
Hello Anca,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Anca
Top achievements
Rank 1
answered on 22 Sep 2015, 08:23 AM

Thank you Konstantin.

Solved my problem. 

Tags
Grid
Asked by
Mattia
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Mattia
Top achievements
Rank 1
Anca
Top achievements
Rank 1
Share this question
or