0

I am new to jQuery, and I need to use a grid in my project. I chose SlickGrid (quite slick indeed). I need to disable certain buttons when rows are deselected.

I am using the following callback:

grid.onSelectedRowsChanged.subscribe(function(){});

The problem is that the callback is only executed on selection - not when rows are deselected.

gmsk19
  • 49
  • 1
  • 6

2 Answers2

0
grid.onSelectedRowsChanged.subscribe(function(){
     var selectedRows = grid.getSelectedRows();
     if (selectedRows.length === 0) {
          // (when all rows are deselected)
          // your logic goes here...
     }
});

If you want to execute logic on any row deselect I suggest storing selectedRows in global variable which would be updated on SelectedRowsChanged event. Also in onSelectedRowsChanged you could compare your global selectedRows variable and grid.getSelectedRows() lenghts to see if any changes have occured.

var lastSelectedRows = [];    
grid.onSelectedRowsChanged.subscribe(function(){
     var selectedRows = grid.getSelectedRows();
     if (selectedRows.length < lastSelectedRows.length ) {
        // proceed in finding the actual row by comparing the two arrays
        // the rest of the logic goes here...
      }
      lastSelectedRows =  selectedRows;
 });

!Note that I'm new in the world of Slickgrid and this may not be the best solution. I just think it's worth a try.

0
var lastSelectedRow = null;

grid.onSelectedRowsChanged.subscribe(function () {
    if (lastSelectedRow && lastSelectedRow != grid.getSelectedRows()[0]) {        
        var item = dataView.getItem(lastSelectedRow);
        // Do something with item;
    }

    lastSelectedRow = grid.getSelectedRows()[0];

    // other logic may go here
});
Ivo Nikolov
  • 81
  • 1
  • 1