gpt4 book ai didi

select - Dojo dgrid :(预)在渲染中选择行

转载 作者:行者123 更新时间:2023-12-04 18:06:22 28 4
gpt4 key购买 nike

如何配置dgrid及其存储以定义渲染行时是否已经选择了行?

例如,如果我的行数据是这样的:

{
id: 1,
name: 'Item Name',
selected: true
}


我当前的代码是在商店填充后遍历整个集合,但是我确信必须有一种更有效的方法来执行此操作。

var items = [
{id: 1, name: 'Item 1', selected: true},
{id: 2, name: 'Item 2', selected: false}
];

require(
[
"dgrid/OnDemandGrid",
"dgrid/Selection",
"dojo/store/Memory",
"dojo/_base/declare",
"dojo/_base/array"
],

function (OnDemandGrid, Selection, Memory, declare, array) {
var store = new Memory({
data: items,
idProperty: "id"
});

var grid = new declare([OnDemandGrid, Selection])({
selectionMode: "multiple",
columns: {
id: { label: "ID" },
name: { label: "Name" }
},
store: store
}, "MyGrid");

array.forEach(items, function (item) {
if (item.selected) {
grid.select(grid.row(item.id));
}
});

grid.startup();
});
}
);

最佳答案

看来Selection.js的用法与https://github.com/SitePen/dgrid/blob/master/Selection.js#L433相同,但是我才有了一个主意,如何使选择成为渲染过程的一部分:

var grid = new declare([OnDemandGrid, Selection])({
selectionMode: "multiple",
store: store,
columns: {
id: {
label: "ID",
get: function(item) {
var grid = this.grid;
if (item.selected === true) {
grid.select(grid.row(item.id));
}
return item.id;
}
},
name: { label: "Name" }
},
"MyGrid"
);


实际观看: http://jsfiddle.net/phusick/stxZc/

关于select - Dojo dgrid :(预)在渲染中选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14757504/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com