3

I got two slickGrids in one object:

instances: {
  registered: {
    selector: '##one',
    slickGrid: null
  },
  registeredPending: {
    selector: '##two',
    slickGrid: null
  }
}

Both of them are filled with data gotten from an AJAX request and the grid is created:

success: function(ajaxData) {
    var data = [];
    // ... parse ajaxData to data

    //instance is either instances.registered or instances.registeredPending
    instance.slickGrid = new Slick.Grid(instance.selector, data, grid.columns, grid.options);
    instance.slickGrid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow: false}));
    instance.slickGrid.registerPlugin(checkboxSelector) //Add checkbox plugin
    instance.slickGrid.onSelectedRowsChanged.subscribe(function(e, data){
        //data.grid is last created slickGrid instance, instead of slickGrid of selected rows
        //It seems data.rows are the selected rows of the right slickGrid table!
    }
}

Everything works fine only the subscribtion to an onSelectedRowsChanged event does not work as supposed to be. The event does respond well, but it returns the last created instance instead of the instance of the changed rows.

Edit

To be clear, both instances are made after a succes callback of a AJAX event. So in my case, two calls are made, both return data; after that a grid is created to represent the data.

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78
  • I think that you mean to add the event on the ObjectType, not on the ObjectInstance. You want to define the function once, and call it whenever. `Slick.Grid.onSelected.subscribe(function(e, data){});` – EricG Dec 19 '13 at 10:40
  • @EricG: According to documentation (https://github.com/mleibman/SlickGrid/wiki/Grid-Events), you need to subscribe to an gridInstance. Would be logical to me, as every instance would be in it's own scope (and listening to it's own bindings). – Jacob van Lingen Dec 19 '13 at 11:08
  • Oke I get it. But then, aren't you subscribing the wrong instance..? – EricG Dec 19 '13 at 14:51
  • No, i add the listener after callingg to the registerPlugin function (inside the succes function). Edited my code, my description could lead to EricG's assumption. – Jacob van Lingen Dec 19 '13 at 16:12

1 Answers1

0

I found the problem after I read this Google Group page: https://groups.google.com/forum/#!topic/slickgrid/mKZzBxl2cVM.

I did have two instances, but both of them registered the Checkboxselectcolumn plugin with the same checkboxSelector variable. So the results got intertwined.

Knowing that, fixing it was easy. Add a variable per instance:

instances: {
   registered: {
     selector: '##one',
     slickGrid: null,
     checkboxSelector: new Slick.CheckboxSelectColumn({ cssClass: "slick-cell-checkbox" })
   },
   registeredPending: { ... }
}

And use that one when registering your plugin.

success: function(ajaxData) {
   ...
   instance.slickGrid.registerPlugin(instance.checkboxSelector)
}
Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78