我有一个Kendo网格。我想处理输入键向下事件。如果用户在Kendo单元格内按Enter键。必须将焦点放在下一个单元格进入编辑模式。(光标应移动到下一个网格细胞)。 我试过这段代码
$("#list").on("focus", "td", function (e) {
$("input").on("keydown", function (event) {
if (event.keyCode == 13) {
setTimeout(function () {
var curCell = $("#list").find(".k-state-selected")
var eCell = $("#list").find(".k-edit-cell")
curCell.removeClass("k-state-selected");
curCell.removeClass("k-state-focused");
curCell.removeAttr("data-role");
curCell.next().addClass("k-state-selected");
curCell.next().addClass("k-state-focused");
try { $('#list').data('kendoGrid').closeCell(eCell);
} catch (ex) {
}
$('#list').data('kendoGrid').select();
$('#list').data('kendoGrid').editCell(curCell.next());
}, 50);
}
});
});
}
或者有没有办法用enter键覆盖tab键功能(因为tab键可以正常工作)
答案 0 :(得分:0)
请尝试使用以下代码段。
<!DOCTYPE html>
<html>
<head>
<title>Jayesh Goyani</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.bootstrap.min.css" />
<script src="https://kendo.cdn.telerik.com/2015.2.902/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2015.2.902/js/kendo.all.min.js"></script>
</head>
<body>
<div id="list"></div>
<script>
$(document).ready(function () {
function onDataBound(e) {
$("#list").on("focus", "td", function (e) {
$("input").on("keydown", function (event) {
if (event.keyCode == 13) {
setTimeout(function () {
var curCell = $("#list").find(".k-state-selected")
var eCell = $("#list").find(".k-edit-cell")
curCell.removeClass("k-state-selected");
curCell.removeClass("k-state-focused");
curCell.removeAttr("data-role");
curCell.next().addClass("k-state-selected");
curCell.next().addClass("k-state-focused");
try {
$('#list').data('kendoGrid').closeCell(eCell);
} catch (ex) {
}
$('#list').data('kendoGrid').select(); $('#list').data('kendoGrid').editCell(curCell.next());
if ($(curCell.next()).find('select')) {
$($(curCell.next()).find('select')).data("kendoDropDownList").open()
}
}, 50);
}
});
});
}
var savings = [{
month: "January",
saving: "$200",
kind: 1
}, {
month: "March",
saving: "$100",
kind: 1
}, {
month: "March sdjhf as dfjh;as",
saving: "$100",
kind: 1
}, {
month: "March",
saving: "$100",
kind: 1
}, {
month: "March",
saving: "$10000",
kind: 1
}, {
month: "December",
saving: "$100",
kind: 1
}, {
month: "March",
saving: "$100",
kind: 1
}, {
month: "March",
saving: "$100",
kind: 2
}, {
month: "March",
saving: "$100",
kind: 3
}, {
month: "March",
saving: "$100",
kind: 1
}];
var savingsDataSource = new kendo.data.DataSource({
data: savings
});
var grid = $("#list").kendoGrid({
dataSource: savingsDataSource,
navigatable: true,
pageable: true,
height: 400,
selectable: "cell",
toolbar: ["create", "save", "cancel"],
columns: [{
field: "month",
title: "Month"
}, {
field: "saving"
}, {
field: "saving"
}, {
field: "kind",
values: [{
value: 1,
text: "Kind1"
}, {
value: 2,
text: "Kind2"
}, {
value: 3,
text: "Kind3"
}]
}],
editable: true,
dataBound: onDataBound,
}).data("kendoGrid");
var specialKeys = [kendo.keys.UP, kendo.keys.DOWN];
function edit(e) {
//$("#list").find(".k-state-selected").focus();
//e.container.find("td:eq(1) input").focus();
}
});
</script>
</body>
</html>
如果有任何疑虑,请告诉我。
答案 1 :(得分:0)
$("#GridID").keypress(function (e) {
if (e.keyCode === 13) {
e.preventDefault();
}
});
请参阅运行代码:
https://www.telerik.com/forums/how-to-prevent-kendo-validation-on-pressing-enter-key