我使用dgrid以网格格式显示数据,它有四列.一切都是可编辑的 我用以下方式声明它. table id="grid" data-dojo-type="dgrid.CustomGrid" data-dojo-props="store: memoryStore"thead tr th data-dgrid-column="dgrid.editor({
我用以下方式声明它.
<table id="grid" data-dojo-type="dgrid.CustomGrid" data-dojo-props="store: memoryStore">
<thead>
<tr>
<th data-dgrid-column="dgrid.editor({ field: 'id' }, dijit.form.TextBox, 'click')">ID</th>
<th data-dgrid-column="dgrid.editor({ field: 'name' }, dijit.form.TextBox, 'click')">Name</th>
<th data-dgrid-column="dgrid.editor({ field: 'description' }, dijit.form.TextBox, 'click')">Description</th>
</tr>
</thead>
</table>
我的问题是,当我编辑第一列时,编辑后应将焦点设置在第二列并在该单元格中显示光标,以便我可以开始编辑第二列;同样是第三列.
我对dojo和dgrid非常新.我在sitepen上找到了一些API,但无法解决我的问题
请帮帮我
有dgrid / Grid :: edit(cell)方法开始.我使用dojo / aspect :: after将一个事件监听器添加到编辑器小部件(例如dijit / form / TextBox),如果它不存在,则监听特定键的keypress事件,在我的情况下是TAB,然后调用grid .edit(单元格)与下一个应该编辑的单元格.
请参阅jsFiddle的一个工作示例:http://jsfiddle.net/phusick/2jU7R/
它还远没有完成,但至少它可以提供一个可能的直接.使用双击编辑并在编辑时按TAB跳转到下一个单元格.
aspect.after(grid, "edit", function(promise, cellNode) {
if(promise === null) return;
promise.then(function(widget) {
if (!widget._editorKeypressHandle) {
widget._editorKeypressHandle = widget.on("keypress", function(e) {
for (var rowId in grid.selection) { break;}
for (var columnId in grid.selection[rowId]) { break;}
if(e.charOrCode == keys.TAB) {
e.preventDefault();
var cellEdited = grid.cell(rowId, columnId);
var cellToEdit = grid.right(cellEdited, 1);
if(cellEdited.row.id == cellToEdit.row.id
&& cellEdited.column.id == cellToEdit.column.id
) {
// go to next line
for(var firstColumnId in grid.columns) { break;}
var nextRow = grid.down(cellEdited.row, 1);
cellToEdit = grid.cell(nextRow, firstColumnId);
};
grid.deselect(cellEdited);
grid.select(cellToEdit);
grid.edit(cellToEdit);
}
})
}
});
});
