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

Grid Loses Selection on Sort

1 Answer 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 05 Apr 2012, 02:39 PM
Hi,

The grid loses the selection (highlighting) on sorting, is there any way to retain the selection on sort or default selection to first row after sort is done?

J

1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 05 Apr 2012, 02:45 PM
I would also like an answer to the first part of the question, but changing it to selecting the first item is relatively easy:

On the grid's dataBound event, do the following:
grid.select($("gridName tbody>tr").not(".k-grouping-row").first());

(The .not() can be removed if the grid isn't groupable).

Again, I'd much prefer a way to maintain the currently selected item, but I'm not entirely sure how.


EDIT: A bit of playing around and I was able to come up with the following:
In a variable somewhere that won't go out of scope between events, store grid.select().text(); on Grid Changed.
On dataBound, do the following:
    grid.select($("tr:contains('" + variableName + "')"));

Probably not the most efficient solution, but it works.
Tags
Grid
Asked by
J
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or