在Ext4.1中的grid默認只能實現單選的。
如果你想要你的grid有多選功能,需要給grid增加selModel
如果你使用了Ext.create('Ext.selection.CheckboxModel')-->selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"})
部分代碼:
1 this.grid= new Ext.grid.GridPanel({ 2 title : 'users', 3 store : this.userStore, 4 columns : [ { 5 header : "用戶ID", 6 sortable : true, 7 dataIndex : 'userId' 8 }, { 9 header : "用戶名稱", 10 sortable : true, 11 dataIndex : 'userName' 12 } ], 13 stripeRows : true, 14 manageHeight:true, 15 height:this.height-114, 16 selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"}),
界面效果:
但是這種方式會出現復選框,
如果不想有復選框是需要把selModel換成Ext.create('Ext.selection.RowModel',{mode:"SIMPLE"})就ok了
如圖:
獲得選中的數據用var records = this.grid.getSelectionModel().getSelection();就可以了