最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Kendo UI, How to manually call validate() on kendo grid cell - Stack Overflow

programmeradmin0浏览0评论

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

the way to invoke validator remended 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

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

the way to invoke validator remended 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

Share Improve this question edited Apr 5, 2014 at 11:33 sztepen asked Apr 4, 2014 at 14:42 sztepensztepen 1332 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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 e 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!

发布评论

评论列表(0)

  1. 暂无评论