【发布时间】:2012-05-16 07:47:18
【问题描述】:
是否可以使用由数组(而不是数据存储区)支持的 Dojo dgrid 小部件和复选框来选择行?
我成功地从一个基本的数组支持的 dgrid 开始,然后添加了 Selection mixin 以启用行选择。所以现在我有一个由数组支持并允许行选择的 dgrid。但是,当我尝试通过 selector column plugin 添加复选框时,出现错误:this.store is undefined.
我确定 this.store 用于识别选择了哪些行:对 this.store.getIdentity(rowObject) 方法的多次调用与查询网格选择时返回的结果直接相关。
当使用对象数组而不是存储时,是否可以指定某个列字段来标识选定的行?我下面代码中的 WORKAROUND_STORE 有效地做到了这一点,但也许我错过了一个简单的解决方案,比如设置一些属性,例如:selector({idProperty: 'col1'}). 看起来应该更容易做到。
require(["dgrid/Grid",
"dgrid/selector",
"dgrid/Selection",
"dojo/_base/declare"],
function(Grid, selector, Selection, declare){
var columns = {
col1: selector({}),
col2: {label: 'COL2'},
col3: {label: 'COL3'},
};
var data = [
{ col1: '1', col2: 'A', col3: 'I'},
{ col1: '2', col2: 'B', col3: 'II'},
{ col1: '3', col2: 'C', col3: 'III'}
];
WORKAROUND_STORE = {
getIdentity: function(item) { return item.col1 }
}
var SelectionGrid = declare([Grid, Selection]);
window.methodGrid = new SelectionGrid({
store: WORKAROUND_STORE,
columns: columns,
selectionMode: "none",
allowSelectAll: true
}, "methodGridDiv");
window.methodGrid.renderArray(data);
}
);
【问题讨论】:
标签: javascript dojo widget dgrid