Ext JS获取网格的选定行

时间:2013-07-01 07:20:58

标签: extjs grid

someButton点击事件中,我希望在事件处理程序中依赖于someGridDo something。我怎样才能做到这一点?我尝试使用

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

这两行代码都返回空对象。

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 个答案:

答案 0 :(得分:2)

您正在寻找的是:

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
             });
      }
    }
 }
}

在items数组中,您将获得所有选定记录的处理。这里我只推送了两列数据。您也可以添加其他列。

答案 1 :(得分:0)

要使用getSelectionModel,您必须SelectionModel 所以你必须添加以上内容。

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

上述内容适用于RowSelection。如果要使用复选框,还有其他示例。 上面的xml取自ext.net。

相关问题