Slickgrid with CheckboxSelectColumn plugin how to maintain checked state with cookies

1.4k Views Asked by At

I would like to implement saving and restoring checked state (check and uncheck) rows in my slickgrid.

The row checked state should be persisted to cookie. after pagination or page reloading checkboxes should be restored.

Where to start (slick.rowselectionmodel.js or slick.checkboxselectcolumn.js?)

1

There are 1 best solutions below

0
On

You can access and restore the selected rows pretty easily, but it might be better to use localStorage rather than a cookie:

window.onbeforeunload = function(){
  var rows = grid.getSelectedRows();
  if (+rows) localStorage['selectedRows'] = JSON.stringify(rows);
  else delete localStorage['selectedRows'];
}

Then when you initialize the grid:

var grid = new Slick.Grid('#myGrid', data, columns, options);
grid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow: false}));
grid.registerPlugin(checkboxSelector);
if ('selectedRows' in localStorage) {
  var rows = JSON.parse(localStorage['selectedRows']);
  grid.setSelectedRows(rows);
}