DojoX Grid 动态添加一行并编辑数据
您可以使用DojoX Grid的store来动态添加一行并进行编辑。下面是一个示例代码:
require([
"dojo/_base/lang",
"dojo/_base/array",
"dojo/store/Memory",
"dojox/grid/DataGrid",
"dojox/grid/cells/dijit",
"dojo/dom",
"dojo/domReady!"
], function(lang, arrayUtil, Memory, DataGrid, cells, dom){
// 创建一个空的store
var store = new Memory({data: []});
// 创建grid
var grid = new DataGrid({
store: store,
structure: [
{name: 'ID', field: 'id', width: '50px'},
{name: '姓名', field: 'name', width: '100px', editable: true, cellType: cells.TextBox},
{name: '年龄', field: 'age', width: '100px', editable: true, cellType: cells.TextBox}
]
}, 'grid');
// 渲染grid
grid.startup();
// 添加一行数据
var newRow = {id: 1, name: 'John Doe', age: 30};
store.put(newRow);
// 编辑数据
grid.edit.apply(grid, [1, 'name']);
});
在这个示例中,我们首先创建了一个空的Memory store,然后创建了一个DataGrid,并将store设置为grid的数据源。我们通过定义structure来指定grid的列的显示方式。
然后,我们使用store的put方法来添加一行数据。在这个例子中,我们添加了一个带有ID、姓名和年龄字段的新行。
最后,我们使用grid的edit方法来编辑刚刚添加的行的'name'字段。这将开启grid的编辑模式,让用户可以修改该字段的值。
请注意,这只是一个简单的示例,仅展示了动态添加一行并进行编辑的基本思路。您可以根据您的具体需求进行相应的调整和扩展。
原文地址: https://www.cveoy.top/t/topic/pZNU 著作权归作者所有。请勿转载和采集!