我们使用Kendo网格作为带有数据输入表单和可编辑网格的标题/明细会计应用程序。当从表单到网格的选项卡时,第一个单元格将不会进入编辑模式,除非在'navigate'事件中有一些解决方法'hack'代码(见下文)。问题是,当从表单输入字段到相同单元格中单击时,网格编辑模式从字面上有所不同。单击(而不是跳转到)第一个单元格会将单元格置于编辑模式,但会清除字段内容。
用户可以标记到网格的第一个单元格或单击其中以编辑单元格的所需行为。
以下是网格的屏幕截图,其中第一个单元格已聚焦,但未处于编辑模式(没有解决方法'hack'代码):
这是网格代码:
let grid = $("#" + target).kendoGrid({
dataSource: {
data: rows,
schema: {
model: {
fields: columnSetup.modelFields
}
}
},
edit: function (e) {
// This does not fire when tabbing to the grid. It will fire if a cell is clicked.
},
editable: {
mode: "incell",
createAt: 'bottom'
},
navigatable: true,
navigate: function (e) {
// Attempted Workaround - This does put the first cell in edit mode, but only when tabbing
// to the grid. However, clicking in the first cell does put the cell in edit mode, but
// clears the field value.
if (e.sender['_rowVirtualIndex'] == 0 && e.element[0]['cellIndex'] == 0 && typeof (e.sender['_editContainer']) != 'object') {
this.editCell(e.element[0])
}
},
resizable: true,
reorderable: true,
scrollable: { virtual: true },
selectable: "row",
columns: columnSetup.columns,
dataBound: keyboardEventHandler,
}).data('kendoGrid');
答案 0 :(得分:0)
要通过点击和标签导航到网格,然后立即进入编辑模式,请使用kendoHelpers' refreshAndKeepEditing'功能导航'网格上的事件:
navigate: function (e) {
if (e.sender['_rowVirtualIndex'] == 0 && e.element[0]['cellIndex'] == 0 && typeof (e.sender['_editContainer']) != 'object') {
this.editCell(e.element[0]);
kendoHelpers.grid.refreshAndKeepEditing(grid, true);
}
},