0
votes

I am using Kendo UI for Jquery in MVC. Below code working fine to move next cell with "Enter" and "Tab" key press event but doesn't work validation with key press event, so if any has solution please share with me. Editable mode is "incell".

Thanks in advance !

$("#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
can you comment on what part of this script ( validation ) isn't working? - Keith
@Keith I am using require validation in Kendo Grid schema like "DayId: { type: "number" , validation: { required: true } }" but doesn't work with above code. - Decimal

1 Answers

0
votes

Finally, I have resolved my an issue by following code. I hope this will help someone.

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