验证对Jquery

时间:2018-06-04 13:11:13

标签: kendo-ui kendo-grid

我在MVC中使用Kendo UI for Jquery。下面的代码工作正常,用“Enter”和“Tab”按键事件移动下一个单元格,但是按键事件没有工作验证,所以如果有任何解决方案请与我分享。 可编辑模式为“incell”。

提前致谢!

$("#grdSalesManRoute").data("kendoGrid").addRow();
    var grid = $("#grdSalesManRoute").data('kendoGrid');
    $(grid.tbody).on("keydown", "td", function (e) {

        if (e.keyCode == kendo.keys.ENTER || e.keyCode == kendo.keys.TAB || (e.shiftKey && e.which == kendo.keys.TAB)) {
            debugger;
            if (e.keyCode == kendo.keys.TAB) {
                e.preventDefault()
            }

            if (e.keyCode == kendo.keys.ESC) {
                colIndex++;
                direction = "h";
            }

            var row = $(this).closest("tr");
            var rowIndex = $("tr", grid.tbody).index(row);
            var colIndex = $("td", row).index(this);
            var direction = "";
            grid.closeCell();
            if (e.shiftKey && e.which == kendo.keys.TAB) {
                colIndex--;
                direction = "h";
            }
            else if (e.keyCode == kendo.keys.ENTER || e.keyCode == kendo.keys.TAB) {
                colIndex++;
                direction = "h";
            }

            if (colIndex == 0 && rowIndex < $("#grdSalesManRoute").data("kendoGrid").dataSource.total()) {
                rowIndex--;
                colIndex = 4;
            }
            else if (colIndex == 5) {
                if ($("#grdSalesManRoute").data("kendoGrid").dataSource.total() - 1 > rowIndex) {
                    rowIndex++;
                    colIndex = 1;
                }
            }

            var cell = $("#grdSalesManRoute tbody tr:eq(" + rowIndex + ") td:eq(" + colIndex + ")");

            if (cell.length > 0) {
                grid.editCell(cell);
            }
            else {
                var cellSelector = "";

                if (direction == "h") {
                    $("#grdSalesManRoute").data("kendoGrid").addRow();
                    // cellSelector = "#grdSalesManRoute tbody tr:eq(" + rowIndex + ") td:eq(1)";
                }
                else {
                    cellSelector = "#grdSalesManRoute tbody tr:eq(0) td:eq(" + colIndex + ")";
                    grid.editCell($(cellSelector));
                }
            }
        }
    });

1 个答案:

答案 0 :(得分:0)

最后,我通过以下代码解决了我的问题。我希望这会对某人有所帮助。

 if ($(".k-edit-cell").data().kendoValidator.validate() == false) {
     return false;
 }