2
votes

On someButton click event I want to get the selected row of someGrid and Do something in event-handler dependent on that. How can I do that? I tried using

var index = someGrid.getSelectionModel().getSelection().selectedIndex; 
var index = someGrid.getSelectionModel().getSelection().selected;

Both of this lines of code return empty objects.

flex: 1,
                xtype: 'grid',
                style: 'margin: 10px 5px;',
                store: 'CL.Store.VendorServiceLimits',
                itemId: 'vendorServiceLimitsGrid',
                columns: [
                    { text: Labels.Vendors.MIN_AMOUNT, dataIndex: 'MinOperationAmount', flex: 1 },
                    { text: Labels.Vendors.MAX_AMOUNT, dataIndex: 'MaxOperationAmount', flex: 1 },
                    { text: Labels.Vendors.MAX_TRANS_PER_DAY, dataIndex: 'MaxOperationsPerDay', flex: 1 },
                    { text: Labels.Vendors.OPERATION_TYPE, dataIndex: 'OperationType', flex: 1 },
                    { text: Labels.Vendors.PERIOD, dataIndex: 'Period', flex: 1 },
                    { dataIndex: 'Id', hidden: true }
                ],
2
Please provide grid's code. - kostas ch.
As i see you create it dynamically. So you need to create something like this: <SelectionModel> <ext:RowSelectionModel ID="RowSelectionModel1" /> </SelectionModel> - kostas ch.
Can you use store.indexOf(record) in conjunction with selModel.getSelection()? i.e. store.indexOf(grid.getSelectionModel().getSelection()[0]) - kevhender
@kevhender +props for the grid.getSelectionModel().getSelection()[0] reminder. Was trying to quickly find that when I came here. - Meredith

2 Answers

2
votes

Is is what you are looking for :

listeners:{
 click:function(){
       var grid = Ext.getCmp('grid');
       var selection= grid.getSelectionModel(); 
       items=[];
       for(i=0;i < grid.store.getCount();i++){  
          if(selection.isSelected(i)){
            items.push({ 
               "MinOperationAmount"   : grid.store.getAt(i).data.MinOperationAmount,
               "MaxOperationAmount"   : grid.store.getAt(i).data.MaxOperationAmount
             });
      }
    }
 }
}

In items array,you will be getting handle to all the selected records.Here i have pushed only two columns data.You can add other columns too.

0
votes

In order for using getSelectionModel you must have SelectionModel So you have to add the above.

 <SelectionModel>
            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
  </SelectionModel>

The above is working for RowSelection. There are other examples if you want to use checkbox. The above xml is taken from ext.net.