【问题标题】:Add empty row to dojox/grid/DataGrid将空行添加到 dojox/grid/DataGrid
【发布时间】:2013-04-09 21:57:48
【问题描述】:
<div id="gridDiv"></div>
<button id="addRow"  data-dojo-type="dijit.form.Button">Add Row</button>


require(['dojo/_base/lang', 'dojox/grid/DataGrid' , 'dojo/data/ItemFileWriteStore' , 'dojo/dom' , 'dojo/domReady!'],
  function(lang, DataGrid, ItemFileWriteStore, Button, dom){
    /*set up data store*/
    var data = {
      identifier: "id",
      items: []
    };

    var store = new ItemFileWriteStore({data: data});

    /*set up layout*/
    var layout = [[
      {'name': 'Column 1', 'field': 'id', 'width': '100px'},
      {'name': 'Column 2', 'field': 'col2', 'width': '100px'},
      {'name': 'Column 3', 'field': 'col3', 'width': '200px'},
      {'name': 'Column 4', 'field': 'col4', 'width': '150px'}
    ]];

    /*create a new grid*/
    var grid = new DataGrid({
        id: 'grid',
        store: store,
        structure: layout,
        rowSelector: '20px'});

    /*append the new grid to the div*/
    grid.placeAt("gridDiv");

    /*Call startup() to render the grid*/
    grid.startup();
});
  • 我有一个以编程方式创建的 dojox/grid/DataGrid,其中没有数据(空存储)。只有布局。
  • 我在网格外有一个按钮。
  • 我的需要是,单击按钮时,我需要在网格中添加一个空行。那个空行不应该来自json。它应该来自商店。
  • 这意味着单击按钮,应向存储添加一个空行,然后将网格与该存储一起加载。有可能吗?

【问题讨论】:

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


    【解决方案1】:

    This fiddle 在单击按钮时将新项目添加到商店。并且网格会自我更新以反映商店的新内容。

    代码的核心是这样的:

    var id = 0;
    
    var button = new Button({
        onClick: function () {
            store.newItem({
                id: id,
                col2: "col2-" + id,
                col3: "col3-" + id,
                col4: "col4-" + id
            });
            id++;
        }
    }, "addRow");
    

    屏幕截图(按 2 次按钮后):

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      • 2014-07-17
      相关资源
      最近更新 更多