晨港飞燕的博客

extjs学习之Ext.selection.CheckboxModel



Ext.onReady( function() {
var store=Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['id','name','description','action'],
data:[{
"id":'1',
"name" : "节目一",
"description" : "lisa@simpsons.com",
"action":'false'
},{
"id":'2',
"name" : "节目二",
"description" : "mary@simpsons.com",
"action":'true'
},{
"id":'3',
"name" : "节目三",
"description" : "jun@simpsons.com",
"action":'false'
}],
proxy: {
type:'memory',
reader: {
type:'json'
}
}
});

var grid=Ext.create('Ext.grid.Panel', {
renderTo : Ext.getBody(),
width : 450,
height : 250,
margin : '0 0 0 100',
store:store,
columns:[{
header:'姓名',
dataIndex:'name',
flex:1
},{
header:'描述',
dataIndex:'description',
flex:1
}],
selModel: Ext.create('Ext.selection.CheckboxModel', {
injectCheckbox:1,//checkbox位于哪一列,默认值为0
mode:'single',//multi,simple,single;默认为多选multi
checkOnly:true,//如果值为true,则只用点击checkbox列才能选中此条记录
allowDeselect:true,//如果值true,并且mode值为单选(single)时,可以通过点击checkbox取消对其的选择
enableKeyNav:false,
listeners: {
deselect: function(model,record,index) {//取消选中时产生的事件
},
select: function(model,record,index) {//record被选中时产生的事件
record.get('name');//选中的节目名称
},
selectionchange: function(model,selected) {//选择有改变时产生的事件

var records=model.getSelection();
if(records!='') {
for(var i in records) {
records[i].get('name')//选中的节目名称(方法一)
}
}

if(selected!='') {
for(var p in selected) {
selected[p].get('name') //选中的节目名称(方法二)
}
}
}
}
})
})
})
posted @ 2016-05-31 13:06  晨港飞燕  阅读(2883)  评论(0编辑  收藏  举报