我们公司不久前从dojox/DataGrid
转移到了dgrid
。现在我们发现,dgrid似乎不支持开箱即用的dijit/dojox小部件。
dojox/DataGrid
有一个formatter()
,它可以返回一个小部件。太容易了!API在GitHub上的比较表明
"dgrid支持格式化程序函数,但不支持返回dgrid还有renderCell返回一个DOM节点。这表面上可以用于显示小部件(编辑器列插件正是这样做的)。请注意出于单元格编辑的目的,编辑器列插件的使用非常频繁鼓励。">
具体如何
我已经尝试过将编辑器插件与{editor: ' ', editorArgs:' '}
一起使用。这确实呈现了一个小部件,但限制性太强。例如,如果dijit/Button
的标签是单元格的值,我该如何呈现它?或者更复杂的事情,我如何使用(鲜为人知的)dojox/image/MagnifierLite
和从格式化程序函数生成的<img>
,其中src
是存储的值?
您可以使用此示例代码
require(
[
"dgrid/List",
"dgrid/OnDemandGrid",
"dgrid/Selection",
"dgrid/editor",
"dgrid/Keyboard",
"dgrid/tree",
"dojo/_base/declare",
"dojo/store/JsonRest",
"dojo/store/Observable",
"dojo/store/Cache",
"dojo/store/Memory",
"dijit/form/Button",
"dojo/domReady!"
],
function(
List,
Grid,
Selection,
editor,
Keyboard,
tree,
declare,
JsonRest,
Observable,
Cache,
Memory,
Button
) {
var columns = [
{
label:"Actions",
field:"id",
width: "200px",
renderCell: actionRenderCell
}
];
var actionRenderCell = function (object, data, cell) {
var btnDelete = new Button({
rowId : object.id,
label: "Delete",
onClick: function () {
myStore.remove(this.rowId);
}
}, cell.appendChild(document.createElement("div")));
btnDelete._destroyOnRemove = true;
return btnDelete;
}
grid = new (declare([Grid, Selection, Keyboard]))({
store: myStore,
getBeforePut: false,
columns: columns
}, "grid");
}