Using slickgrid, I need to select/deselect rows on the fly, and here is my code, it seems to work but sounds a bit suboptimal really, is there any smater means to do this ?
// turn records checkbox on or off depending on 'checked'
function set_checkbox (record, checked) {
var id = record[primary_key];
var index = dataview.getIdxById(id);
var selectedRows=this.slick_grid.getSelectedRows();
if (checked) // add index in current list
selectedRows=selectedRows.concat(index);
else // remove index from current list
selectedRows=selectedRows.filter(function(idx) {return idx!=index;});
this.slick_grid.setSelectedRows(selectedRows);
}
The grid is initialized with this selection model here:
grid.setSelectionModel (new Slick.RowSelectionModel ({selectActiveRow: false}));