jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 如何通过按Enter键将下一个单元格集中在kendo网格中大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<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",destroy: {
                                    url: crudserviceBaseUrl + "/Products/Destroy",create: {
                                    url: crudserviceBaseUrl + "/Products/Create",parameterMap: function (options,operation) {
                                    if (operation !== "read" && options.models) {
                                        return { models: kendo.Stringify(options.models) };
                                    }
                                }
                            },batch: true,pageSize: 20,scheR_253_11845@a: {
                                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,dataBound: onDataBound,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",{ field: "DisconTinued",//                            { field: "",title: "No",template: "#= ++record #",width: "30px" },{Command: ["destroy"],title: "&nbsp;",width: "100px"}],editable: true
        });
    });
</script>
<script>
    function onDataBound(E) {
        var grid = $("#batchgrid").data("kendoGrid");
        $(grid.tbody).on("keydown","td",function (E) {
            if ((e.keyCode ? e.keyCode : e.which) == 13) { //Enter keycode
                var row = $(this).closest("tr");
                var rowIdx = $("tr",grid.tbody).index(row);
                var colIdx = $("td",row).index(this);
                alert(rowIdx + '-' + colIdX);

                $this.closest('tr').next().find('td').eq(indeX).focus();
                e.preventDefault();
            }
        });
    }
</script>@H_616_6@ 
 

在这里,当我在编辑模式下按下回车键(插入新记录)时,我需要进入下一个单元格(就像我按Tab键一样).

以及如果我按任何行的最后一个单元格(最后一列)中的回车键,它应移动到下一行的第一个单元格(第一列).

我认为问题在我的脚本中.但不知道确切的位置.

请帮帮我..

解决方法

试试这个代码: –

<script>

$(document).ready(function(){

$("#KendoGridName").keypress(function(E){

var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                    var grid = $("#KendoGridName").data("kendoGrid");
                    var curCell = grid.find(".k-edit-cell");
                    grid.editCell(curCell.next()); // To move the cursor to the next cell and put the cell in edit mode
                    grid.SELEct(curCell.next()); // To SELEct the next cell
                    grid.focus(curCell.next()); // To set focus on to next cell   
                    e.preventDefault(); // To prevent the default behavior of the enter key press
                }
});

});

</script>@H_616_6@ 
 

注意: – 您也可以使用keydown函数(E){}代替按键功能(E).

如果代码不起作用或有一些缺陷,请通过您的意见.我在MVC5中试过这个,它与Kendo Grid一起工作.

大佬总结

以上是大佬教程为你收集整理的jquery – 如何通过按Enter键将下一个单元格集中在kendo网格中全部内容,希望文章能够帮你解决jquery – 如何通过按Enter键将下一个单元格集中在kendo网格中所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。