我正在研究如何覆盖 Kendo 网格的一些默认键盘命令。正如我的example ,并且正在拦截回车键,并希望按照以下代码块中的操作向下移动一个单元格..
if (e.keyCode == 13) { // enter
var current = grid.current();
var index = current.index();
var next = $(current).closest('tr').next('tr');
var td = next.find('td:eq(' + index + ')');
grid.closeCell();
grid.current(td);
current = grid.current();
grid.focus(current);
//current.focus();
return;
}
距离上类已经很近了。如果我在按 Enter 键之前处于导航模式,那么一切仍然可以正常工作。但是,如果我处于编辑模式(例如,按 Tab 键切换到单元格,然后按 Enter 键),它确实会向下移动单元格并返回导航模式,但我似乎没有正确的重点。左右箭头键不起作用,向上和向下箭头似乎显示焦点位于页面上,而不是网格内。
我尝试过以各种方式调用焦点,但我就是无法让它工作。有什么想法我在这里做错了吗?任何帮助将不胜感激!
提前致谢
最佳答案
您需要将焦点设置在表格本身上,因为网格的 keydown 事件处理程序绑定(bind)到表格:
scope.$on("kendoRendered", function (e) {
var grid = scope.grid;
var elem = $(grid.table);
// attach keydown handler to the table
var newHandler = function (e) {
if (e.keyCode == 13) { // enter
var current = grid.current();
var index = current.index();
var next = $(current).closest('tr').next('tr');
grid.closeCell();
var td = next.find('td:eq(' + index + ')');
grid.current(td);
$(td).closest("table").focus();
}
};
$(elem).on("keydown", newHandler);
});
( demo )
关于jquery - 剑道网格 : How to set focus back to a grid cell after canceling current editing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28828228/