Kendo UI, How to manually call validate() on kendo grid cell

China☆狼群 提交于 2021-02-08 15:22:13

问题


Is there a way to call validate() on a cell in kendo-grid without using the editCell() method?

the way to invoke validator recommended by the Telerik team is as follows:

$("myGrid").data("kendoGrid").editable.validatable.validate()

however, no editable object is available if there is no cell open (e.g there is no focused input in the grid), so I have to activate cells one by one to call validate()

I would like to invoke validation on each of the grid cells and run some logic (e.g. addClass())

I succeed if I jquery loop through all td elements in the grid and invoke validate(), like this:

    $(".k-grid-content td").each(function () {
            var cell = $(this);
            grid.editCell(cell);
            if (!grid.editable.validatable.validate()) {
                cell.addClass("cell-invalid");                 
            };
            grid.closeCell(cell);
        });

however this code is not elegant and painfully slow.

What I'm trying to achieve is grid validation on submit.

QUESTION once again: Can I run the kendo validator on each grid cell, without repeatedly entering and leaving the edit mode?

PS: I am using batch edit (incell) mode


回答1:


I looked into this a bit deeper, and was unable to find anything in the grid docs that supports this batch validation natively. The grid format, in general, is meant to handle data on a row-by-row basis, which mirrors relational database table / spreadsheet type of data presentation. With that in mind, a typical insert/edit/validate/delete operation is intended to be performed on a single row, or record, at a time.

My answer is: no. You cannot run the Kendo validation without repeatedly entering and leaving the edit mode for each cell that needs validation.

You might be able to if you could dig into the Kendo JS libraries and figure out exactly how the validation is invoked, and create some custom methods to invoke it in a batch manner. Something like that could likely break as soon as the next Kendo update came out.

To make it faster, you may have to come up with a clever way to validate the data as it is entered; or on blur; or as a "background" task using setTimeout; or packaging the data up and sending it back to the server via Ajax then handling return messages somehow.

Good luck!



来源:https://stackoverflow.com/questions/22865867/kendo-ui-how-to-manually-call-validate-on-kendo-grid-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!