Kendo UI,如何在kendo 网格单元上手动调用validate() [英] Kendo UI, How to manually call validate() on kendo grid cell

查看:19
本文介绍了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 团队推荐的validator 调用方式如下:

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.

我想要实现的是提交时的网格验证.

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

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.

祝你好运!

这篇关于Kendo UI,如何在kendo 网格单元上手动调用validate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆