我使用一些 kendo ui 工具开发了一个简单的Web应用程序。
在那里我使用了 kendo grid 工具来查看和插入产品详细信息的数据。
但我的问题是编辑模式(当我插入新记录时),当我按输入键时,我需要转到下一个单元格(同一行的下一列),然后在最后一列之后转到下一行(新记录)。
这是我在视图“index.cshtml”中使用网格的代码
button class="k-button" id="batchGrid">
Batch Edit</button>
<div id="example" class="k-content">
<div id="batchgrid">
</div>
</div>
<script>
$("#batchGrid").click(function () {
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true} },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true} }
}
}
}
});
$("#batchgrid").kendoGrid({
dataSource: dataSource,
navigatable: true,
filterable: true,
pageable: true,
height: 430,
width: 300,
toolbar: ["create", "save", "cancel"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" },
{ field: "UnitsInStock", title: "Units In Stock", width: "130px" },
{ field: "Discontinued", width: "130px" },
{ command: ["destroy"], title: " ", width: "100px"}],
editable: true
});
});
</script>
如何在剑道网格中处理输入按键事件并浏览列和行?
请在这里帮助我。
答案 0 :(得分:0)
尝试此代码,它可以帮助您在输入按键时移动下一个单元格,
$(document).ready(function () {
$("#batchGrid").on("click", "td", function (e) {
var rowIndex = $(this).parent().index();
var cellIndex = $(this).index();
window.onkeydown = function (event) {
if (event.keyCode == 13) {
$("#batchGrid").data("kendoGrid").editCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").next().focusin($("#batchGrid").data("kendoGrid").closeCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").parent())));
}
}
});
});
答案 1 :(得分:0)
试试这个
$("#batchgrid").on("click", "td", function (e) {
var rowIndex = $(this).parent().index();
var cellIndex = $(this).index();
$(".k-textbox").on("keydown", function (event) {
if (event.keyCode == 13) {
$("#batchgrid").data("kendoGrid").editCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").next().focusin($("#batchgrid").data("kendoGrid").closeCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").parent())));
return false;
}
});
});
答案 2 :(得分:0)
试试这段代码。
$("#batchgrid").on("click", "td", function (e) {
var rowIndex = $(this).parent().index();
var cellIndex = $(this).index();
$("input").on("keydown", function (event) {
if (event.keyCode == 13) {
$("#batchgrid").data("kendoGrid").editCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").next().focusin($("#batchgrid").data("kendoGrid").closeCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").parent())));
return false;
}
});
});