Search code examples
extjs4

Ext.grid.Panel get selected record from tbar button


I created a View extend Ext.grid.Panel and also attach a tbar to it, in the toolbar I got 2 buttons [Add] and [Remove] in this question I am focus on the [Remove] command only.

As usual I want to get hold to current selected record in the grid which I want to delete.

so in the controller:

init: function() {
 this.control({
   'extendgridlist button[action=remove]': {
      click: this.removeCurrentRow;
    }
 });
}

removeCurrentRow: function(t){
 // how do i get current selected record
}

Solution

  • removeCurrentRow: function(t){
     var grid = t.up('gridpanel');
     var arraySelected =grid.getSelectionModel().getSelection();
     //assuming you have a single select, you have the record at index 0;
     var record = arraySelected[0]
    }