Extjs grid select 選取行內容

 var grid = Ext.create('Ext.grid.Panel', {
            renderTo: Ext.getBody(),
            store: store,
            height: 400,
            width:800,
            selModel: { selType: 'checkboxmodel' },   //選擇框
            columns: [                    
                          { text: '型錄ID', dataIndex: 'cataId', align: 'left', maxWidth: 80 },
                          { text: '型錄編號', dataIndex: 'cataNo',  maxWidth: 120 },
                          { text: '助記標題', dataIndex: 'cataTitle', align: 'left', minWidth: 80 },
                          { text: '應用對象', dataIndex: 'cataObjectName', maxWidth: 80, align: 'left' },                        
                          { text: '發佈狀態', dataIndex: 'cataPublishName', maxWidth: 80 },
                          { text: '活動截止日期', dataIndex: 'cataEndDate',xtype:'datecolumn',dateFormat :'Y-m-d H:i:s' },
                          { text: '更新時間', dataIndex: 'holyUpdateTime',xtype:'datecolumn',dateFormat :'Y-m-d H:i:s'},
                          { text: '發佈時間', dataIndex: 'catapushtime',xtype:'datecolumn',dateFormat :'Y-m-d H:i:s'}
                       ],
            bbar: [{
                xtype: 'pagingtoolbar',
                store: store,
                displayMsg: '顯示 {0} - {1} 條,共計 {2} 條',
                emptyMsg: "沒有數據",
                beforePageText: "當前頁",
                afterPageText: "共{0}頁",
                displayInfo: true                 
            }],
             listeners: { 'itemclick': function (view, record, item, index, e) {
               Ext.MessageBox.alert("標題",record.data.cataId);
            }
            },
             tbar:[
             {text:'新增',iconCls:'a_add',handler:showAlert},"-",
             {text:'編輯',iconCls:'a_edit2',handler:showAlert},"-",
             {text:'停用/啓用',iconCls:'a_lock'},"-",
             {text:'發佈',iconCls:'a_upload',handler:showAlert},"-",
             {text:'組織型錄',iconCls:'a_edit',handler:showAlert},"-",
             {text:'管理商品',iconCls:'a_edit',handler:showAlert},"-",
             "->",{ iconCls:"a_search",text:"搜索",handler:showAlert}], 
        });
function showAlert (){
      var selectedData=grid.getSelectionModel().getSelection()[0].data;

      Ext.MessageBox.alert("標題",selectedData.cataId);
 }
}); 


這個只能獲取單行數據
function showAlert (){ var selectedData=grid.getSelectionModel().getSelection()[0].data; Ext.MessageBox.alert("標題",selectedData.cataId); }
這個可以獲取選擇的多行數據
 var rows = grid.getView().getSelectionModel().getSelection();
                var msg = "";
                for (var i = 0; i < rows.length; i++) {
                    msg = msg + rows[i].get('cataId') + ',';
                }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章