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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With