我的要求是在单击添加行按钮时在dataGrid内网格的第一行添加一个新行。我可以在网格内添加新行,但我想 每次用户单击“添加行”按钮时,都会在网格的第一行中添加/显示新行。目前,当用户想要添加新行时,会显示它 在现有行之后,如 fiddle 所示: http://jsfiddle.net/Q9GYv/59/ 。 请建议我如何在现有数据网格的第一行中显示新添加的行,或者如果在最后一行添加,如 fiddle 所示,则将焦点集中在新添加的行上用户。
下面是示例代码:
require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dijit/form/Button', 'dojo/dom', 'dojo/domReady!'],
function (lang, DataGrid, ItemFileWriteStore, Button, dom) {
/*set up data store*/
var data = {
identifier: "id",
items: [{
id : 1,
col2 : "aa",
col3 : "bb",
col4 : "cC"
}]
};
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();
var id = 2;
var button = new Button({
onClick: function () {
console.log(arguments);
store.newItem({
id: id,
col2: "col2-" + id,
col3: "col3-" + id,
col4: "col4-" + id
});
id++;
}
}, "addRow");
});
最佳答案
您可以设置sortInfo
网格属性为-1
它将按第一列降序对网格进行排序,并在 renderRow 之后强制使用 dojo/aspect
进行排序
aspect.after(grid, 'renderRow', grid.sort);
http://jsfiddle.net/RichAyotte/740L0y43/
如果可能,请使用 dgrid 。 dojox/grid/DataGrid
已被或将被弃用。
关于java - 在 dataGrid 内的第一行显示新行或聚焦于新添加的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29174212/