datagrid - dojo dgrid 内的小部件

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

我们公司搬迁自dojox/DataGriddgrid前段时间。现在我们发现,dgrid似乎不支持开箱即用的 dijit/dojox 小部件。

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

"dgrid supports formatter functions, but doesn't support returning a widget from them .dgrid also has renderCell, which is expected to return a DOM node. This could ostensibly be used for displaying widgets (and the editor column plugin does exactly this). Note that for cell editing purposes, use of the editor column plugin is highly encouraged."

具体如何?

我尝试使用 {editor: ' ', editorArgs:' '} 的编辑器插件。这确实渲染了一个小部件,但限制太多。例如,我如何渲染 dijit/Button其标签是单元格的值?或者更复杂的东西,我如何使用(鲜为人知的)dojox/image/MagnifierLite<img>从带有 src 的格式化函数生成是商店的值(value)吗?

最佳答案

您可以使用此示例代码

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

}

关于datagrid - dojo dgrid 内的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13444162/

相关文章:

javascript - 隐藏字段上的 Dojo Onchange 事件

dojo的私有(private)变量

dojo - 第 1 页上的复选框 "ticked"反射(reflect)在 EnhancedGrid 的第 2 页中

swift : Auto Text in Shinobi Grid

c# - WPF DataGrid 无法重现 WindowsForms 数据网格大小调整行为

javascript - Dojo Toolkit store.在 TextBox 内获取值

dialog - 如何以编程方式创建带有 dojox.grid.DataGrid 的 dijit.Dialog

c# - 将 Datagrid 单元格原始值与 CellEditEnding 事件中的编辑值进行比较

c# - WPF Datagrid 多项选择在拖动时丢失

xpages - 如何返回 XPage 上 Dojo DataGrid 中可编辑列的值?