Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SlickGrid selection issues on sort

When using SlickGrids selection and sorting together I found that the selection is storing the index of the selected rows rather than storing the selection for the data you selected.

How can I fix this so that the selected data is remembered instead of just an index?


A demo of the issue can be found here: http://jsfiddle.net/blowsie/LKf6j/

To reproduce the issue take the following steps;

  1. Select the first item in the grid
  2. Sort on name
like image 852
Blowsie Avatar asked Mar 20 '13 10:03

Blowsie


2 Answers

You need to call dataView.syncGridSelection(grid, true).

See https://github.com/mleibman/SlickGrid/wiki/DataView#synchronizing-selection--cell-css-styles

like image 114
Tin Avatar answered Nov 19 '22 23:11

Tin


After digging through a few more of the examples I found this example.

I soon realised to do what I want to achieve I needed to use the Slick.Data.DataView APi with the following code.

                dataView.onRowsChanged.subscribe(function (e, args) {
                    grid.invalidateRows(args.rows);
                    grid.render();
                });



                // initialize the model after all the events have been hooked up
                dataView.beginUpdate();
                dataView.setItems(files);
                dataView.endUpdate();

                dataView.syncGridSelection(grid, true);
like image 21
Blowsie Avatar answered Nov 19 '22 23:11

Blowsie