【问题标题】:Can only edit last row of Dojo DataGrid只能编辑 Dojo DataGrid 的最后一行
【发布时间】:2014-04-10 00:56:47
【问题描述】:

我正在使用一个 dojo 数据网格,它显示从服务器发送的坐标数据或来自添加到 ESRI 地图的引脚的坐标数据。

但是,当我单击单元格编辑文本框时,您可以更改值,但除非您正在编辑最后一行,否则更改不会保存。如果您编辑第 2 行中的文本框,然后单击同一列中最后一行的框,则第 2 行的值将放在最后一行中。

如果您以任何其他方式退出,第 2 行数据将恢复为其原始值。最后一行的行为完全符合我的要求,您可以编辑所有值并将它们保存(除非刷新页面)。如果添加了另一行,并且您尝试对其进行编辑,则该行将抛出一个

“Uncaught TypeError:Cannot read property 'get' of undefined” ObjectStore.js:8 上的错误。

我从 hellodgrid 示例中的代码开始 http://dojotoolkit.org/documentation/tutorials/1.9/working_grid/demo/ 使用“使用网格编辑数据”并编辑任意行中的列。

我还没有遇到过像我这样的问题,我真的很困惑,所以非常感谢任何帮助。

以下代码中的数据是我创建的对象数组。

    function drawTable(data){
        require([
            "dojox/grid/DataGrid",
            "dojox/grid/cells",
            "dojox/grid/cells/dijit",
            "dojo/store/Memory",
            "dojo/data/ObjectStore",
            "dojo/date/locale",
            "dojo/currency",
            "dijit/form/DateTextBox",
            "dojox/grid/_CheckBoxSelector",
            "dojo/domReady!"
        ], function(DataGrid, cells, cellsDijit, Memory, ObjectStore, locale, currency,
            DateTextBox, _CheckBoxSelector){
            function formatDate(inDatum){
                return locale.format(new Date(inDatum), this.constraint);
            }
            gridLayout = [
              {
      type: "dojox.grid._CheckBoxSelector",
      defaultCell: { width: 8, editable: true, type: cells._Widget, styles: 'text-align: right;' }
              }, 
              //cells:
                    [

        { name: 'Number', field: 'order', editable: false /* Can't edit ID's of dojo/data items */ },
                    { name: 'ID', field: 'uniqueID', width: 10, editable: false /* Can't edit ID's of dojo/data items */ },
                    { name: 'Station ID', field: 'stationID', width: 15, editable: true },
                    /* No description for each station... at least not yet
        { name: 'Description', styles: 'text-align: center;', field: 'description', width: 10,
                        type: cells.ComboBox, 
                        options: ["normal","note","important"]},*/
                  { name: 'Road', field: 'road', width: 10, editable: true, styles: 'text-align: center;',
                        type: cells.CheckBox},  
                    { name: 'Route', field: 'route', width: 10, editable: true, styles: 'text-align: center;',
                        type: cells.CheckBox},
                    { name: 'Count Type', width: 13, editable: true, field: 'countType',
                        styles: 'text-align: center;',
                        type: cells.Select,
                        options: ["new", "read", "replied"] },
                    { name: 'Count Duration', field: 'countDuration', styles: '', width: 15, editable: true},
                    /*  
                  May want to use this later                    
                { name: 'Date', field: 'col8', width: 10, editable: true,
                        widgetClass: DateTextBox,
                        formatter: formatDate,
                        constraint: {formatLength: 'long', selector: "date"}}, */

                ]
              //{
            ];


            objectStore = new Memory({data:data});

            stationGridStore = new ObjectStore({objectStore: objectStore});

            //  create the grid.
            grid = new DataGrid({
                store: stationGridStore,
            structure: gridLayout,
    //          rowSelector: '20px',
                "class": "grid"
            }, "grid");
            grid.startup();

//          grid.canSort=function(){return false;};
        });
    }

【问题讨论】:

    标签: javascript datagrid dojo


    【解决方案1】:

    您没有在问题中包含您的实际数据,但根据您的一列,我猜您的数据项将唯一标识符存储在名为 uniqueID 的属性中。但是,dojo/store/Memory 默认情况下假定唯一 ID 在 id 属性中。这种不匹配很可能是导致您的问题的原因。

    您可以通过在实例上设置 idProperty 来通知 dojo/store/Memory 您的唯一标识符在另一个属性下:

    objectStore = new Memory({ data: data, idProperty: 'uniqueID' });
    

    【讨论】:

    • 哇,非常感谢!我不知道它假定了 id 属性。要是每一个修复都这么简单就好了……
    猜你喜欢
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2011-11-10
    相关资源
    最近更新 更多