Kendo UI,如何在Kendo网格单元格上手动调用validate()

Kendo UI,如何在Kendo网格单元格上手动调用validate()

问题描述:

是否可以在不使用 editCell()方法的情况下在 kendo-grid 中的单元格上调用 validate()?

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

Telerik小组建议的调用验证器的方法如下:

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

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

但是,如果没有打开单元格(例如,网格中没有集中的输入),则没有可编辑对象可用,因此我必须通过以下方式激活单元格:一个调用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()

我想在每个网格单元上调用验证并运行一些逻辑(例如 addClass())

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

如果我通过jquery遍历网格中的所有 td 元素并调用 validate(),则成功,如下所示:

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.

问题再次:我可以在每个网格单元上运行kendo验证程序,而无需反复进入和退出编辑模式吗?

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

PS:我正在使用批量编辑(incell)模式

我对此进行了更深入的研究,无法在网格文档中找到任何本机支持此批处理验证的内容.通常,网格格式用于逐行处理数据,这反映了关系数据库表/电子表格类型的数据表示形式.考虑到这一点,典型的插入/编辑/验证/删除操作打算一次在一行上执行,也可以在一条记录上执行.

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.

我的回答是:不.如果不为每个需要验证的单元重复输入和退出编辑模式,则无法运行Kendo验证.

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

如果您可以深入研究Kendo JS库并确切弄清楚如何调用验证,并创建一些自定义方法以批处理方式调用它,您也许可以.下次发布剑道更新时,类似的东西可能会中断.

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.

为使其更快,您可能必须想出一种巧妙的方法来验证输入的数据;或在blur上;或使用setTimeout作为后台"任务;或打包数据并通过Ajax将其发送回服务器,然后以某种方式处理返回消息.

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.

祝你好运!