带有复选框列的 Ext JS 网格面板
我的页面中有一个网格,上面设置了 CheckboxModel。它显示名称和复选框,但我不知道如何将商店中的布尔列绑定到选择模型中的列。我找到了使用 CheckColumn 的示例,但这会引发一个错误,表明它没有构造函数。应该是v4的改动。非常感谢您对此提供一些帮助。
Ext.define('Roles', {
extend: 'Ext.data.Model',
fields: ['Id', 'Name', 'Selected'],
proxy: {
type: 'ajax',
url: '/tpn/Types/AjaxList',
reader: {
type: 'json',
root: 'rows',
totalProperty: 'total',
successProperty: 'success'
},
listeners: {
exception: function (proxy, type, action, options, response, arg) {
Ext.MessageBox.alert('Error', Ext.decode(type.responseText).error);
}
}
}
});
var roleStore = Ext.create('Ext.data.Store', {
model: 'Roles'
});
var sm = Ext.create('Ext.selection.CheckboxModel');
var grid = Ext.create('Ext.grid.Panel', {
store: roleStore,
selModel: sm,
columns: [{
header: 'Name',
dataIndex: 'Name',
flex: 1
}],
renderTo: 'RoleGrid',
autoHeight: false,
height: 200,
frame: false
});
I've got a grid in my page with a CheckboxModel set on it. It's showing the names and checkboxes but I don't know how to bind the boolean column from the store to the column from the selection model. I've found examples using CheckColumn instead but this throws an error that it doesn't have a constructor. Must be a change in v4. Would really appreciate some help with this please.
Ext.define('Roles', {
extend: 'Ext.data.Model',
fields: ['Id', 'Name', 'Selected'],
proxy: {
type: 'ajax',
url: '/tpn/Types/AjaxList',
reader: {
type: 'json',
root: 'rows',
totalProperty: 'total',
successProperty: 'success'
},
listeners: {
exception: function (proxy, type, action, options, response, arg) {
Ext.MessageBox.alert('Error', Ext.decode(type.responseText).error);
}
}
}
});
var roleStore = Ext.create('Ext.data.Store', {
model: 'Roles'
});
var sm = Ext.create('Ext.selection.CheckboxModel');
var grid = Ext.create('Ext.grid.Panel', {
store: roleStore,
selModel: sm,
columns: [{
header: 'Name',
dataIndex: 'Name',
flex: 1
}],
renderTo: 'RoleGrid',
autoHeight: false,
height: 200,
frame: false
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在网格的 afterrender 事件(或绑定存储的 load 事件)上放置一个侦听器,以遍历存储以获取布尔检查值并调用 < strong>GridPanel.selectRecords() 方法来选择 UI 中的所有这些记录。这将检查他们的复选框。
You can place a listener on the afterrender event of your grid (or on the load event of your bound store) to walk the store for the boolean checked value and call the GridPanel.selectRecords() method to select all those records in your UI. This will check their checkboxes.