Extjs在grid中添加checkbox

在grid中增加2个checkbox列
Ext.onReady( function() {
var store=Ext.create('Ext.data.Store', {
storeId:'test',
fields:['id','name','description','action'],
data:[{
"id":'1',
"name" : "节目一",
"description" : "测试一",
"action":'false'
},{
"id":'2',
"name" : "节目二",
"description" : "测试二",
"action":'true'
},{
"id":'3',
"name" : "节目三",
"description" : "测试三",
"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
},{
header:'是否加密',
xtype:'templatecolumn',
tpl:'<input name=action type=checkbox id={id} />'
}],
selModel:Ext.create('Ext.selection.CheckboxModel', {
checkOnly:true
}),
dockedItems:[{
xtype:'toolbar',
dock:'bottom',
ui:'footer',
layout:{
pack:'center'
},
items:[{
text:'保存',
minWidth:80,
handler:function(){
var records=grid.getSelectionModel().getSelection();
var contents='';
for(var p in records){
var id=records[p].get('id');
var action;
if(document.getElementByIdx_x_x(id).checked){
action='1';
}
else{
action='0';
}
contents +=id+','+action+'|';
}
alert(contents)
}
}]
}]
})
})

你可能感兴趣的:(Extjs在grid中添加checkbox)