我有一个包含少量项目和复选框的网格面板。我希望默认情况下检查和读取网格面板中的特定项目(用户不能更改选中的值)。我该怎么做?我的代码如下:
var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
mode : 'SIMPLE',
listeners : {
selectionchange : function(selectionModel) {
}
},
});
var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
storeId: 'userCheckboxStore',
fields: ['data'],
data: [
{ data: 'Item 1'},
{ data: 'Item 2' },
{ data: 'Item 3'},
{ data: 'Item 4'},
{ data: 'Item 5'},
]
});
var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
layout : {
type : 'vbox',
align : 'stretch'
},
defaults : {
border : 0,
bodyStyle : {
backgroundColor : 'transparent'
}
},
store: CheckboxContainersStore,
selModel: MyCheckboxModel,
title: 'Item List',
columns: [
{ dataIndex: 'data'},
]
});
我想要'项目1'默认情况下检查和只读。任何建议将不胜感激
答案 0 :(得分:2)
答案 1 :(得分:1)
另一种实施方式就是这样。
var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
mode: 'SIMPLE',
checkOnly: true,
listeners: {
beforedeselect: function(grid, record, index, eOpts) {
if (record.get('data') == "Item 1") {
return false;
}
}
}
});
var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
storeId: 'userCheckboxStore',
fields: ['data'],
data: [{
data: 'Item 1'
}, {
data: 'Item 2'
}, {
data: 'Item 3'
}, {
data: 'Item 4'
}, {
data: 'Item 5'
},
]
});
var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
layout: {
type: 'vbox',
align: 'stretch'
},
defaults: {
border: 0,
bodyStyle: {
backgroundColor: 'transparent'
}
},
listeners: {
'viewready': function(grid) {
grid.selModel.doSelect(grid.store.data.items[0]);
}
},
store: userCheckboxContainersStore,
selModel: MyCheckboxModel,
title: 'Item List',
columns: [{
dataIndex: 'data'
}],
renderTo: Ext.getBody()
});