dojo dgrid里面的小部件

时间:2012-11-18 20:18:22

标签: datagrid dojo dojox.grid.datagrid dojox.grid dgrid

我们公司一段时间后从dojox/DataGrid转移到dgrid。现在我们发现,dgrid似乎不支持开箱即用的dijit / dojox小部件。

dojox/DataGridformatter()可以返回小部件。在那里很容易做到! API comparison on GitHub

  

“dgrid支持格式化程序函数,但不支持返回a   来自他们的小部件.dgrid也有renderCell,这是预期的   返回一个DOM节点。这表面上可以用于显示   小部件(编辑器列插件就是这样做的)。注意   出于单元格编辑的目的,使用编辑器列插件非常重要   鼓励。“

到底是怎么回事?

我尝试使用{editor: ' ', editorArgs:' '}编辑器插件。这确实渲染了一个小部件但限制性太强。例如,如何呈现dijit/Button,其标签是单元格的值?或者更复杂的东西,我如何使用({1}} dojox/image/MagnifierLite生成<img>格式函数生成src,其中{{1}}是商店的价值?

1 个答案:

答案 0 :(得分:14)

您可以使用此示例代码

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");

}