views:

31

answers:

1

I am using a dojox.grid.DataGrid to display data and allow the user to select one or more rows to highlight items to do other actions to.

My problem is that the grid uses indexes to remember the selected rows. If I have turned clientSort on, sorting the rows makes the rows change order but the selection changes to the rows that now occupy the selection indexes before sorting.

To combat this I get the items for the selected rows on each selection change and then when onSort event happens I use getItemIndex(item) on each of the items in my selected items collection to get the new row indexes and I re-select using those indexes.

Now, my problem is that the DataGrid loads data a certain number of rows at a time (it uses the term page to define a set number of rows) to improve performance. When a sort occurs it reloads the data in the new sort order but only up to the rowsPerPage value (defaults at 40). When I try and use getItemIndex for an item whose new row has not been loaded into the grid it returns and index of -1. The getItemIndex() function only returns the index once the user scrolls down and the row is loaded.

I cannot find an event that fires when the page loading occurs to try and restore the selection. I have looked through the 1.3.2 source code and can not find anything. I have tried connecting to a number of private functions but none work.

Has anyone come across this and found a fix?

Thanks in advance.

A: 

I found the answer. The dojox.grid.DataGrid has a private event (_onFetchComplete) which fires each time the next page is requesting. I use setTimeout to run my restore function after a duration of 300.

Job done!

Jonesy