This is a migrated thread and some comments may be shown as answers.

Custom Validator on a cell, get Value from a different cell

7 Answers 770 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CS
Top achievements
Rank 2
CS asked on 26 Jun 2014, 06:38 AM
I'm currently trying to write a validator that checks the current cell value depending on a value of a none editable cell in the same row. How do I get access to that value in the validator? I tried to mock up an example with some pseudo code.

Custom Validator

7 Answers, 1 is accepted

Sort by
1
Accepted
Vladimir Iliev
Telerik team
answered on 30 Jun 2014, 06:55 AM
Hi Stefan,

Please check the example below of getting other fields from current model using grid API:

productnamevalidation: function (input) {
        var row = input.closest("tr");
        var grid = row.closest("[data-role=grid]").data("kendoGrid");
        var dataItem = grid.dataItem(row);
        alert(dataItem.UnitPrice);
        if (input.is("[name='ProductName']") && input.val() != "") {

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
CS
Top achievements
Rank 2
answered on 30 Jun 2014, 07:16 AM
The dataItem is updating after "update" or "save" action I take it, because when I for example compare the value of two cells with each other they show the unaltered values instead of their current values.
0
Vladimir Iliev
Telerik team
answered on 02 Jul 2014, 05:56 AM
Hi Stefan,

If the dataItem is not updated with the latest changes you can use the same approach and get the needed value by finding the other field editor by it's name attribute (which should be equal to the corresponding field name).

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
CS
Top achievements
Rank 2
answered on 02 Jul 2014, 06:25 AM
Yes, but not editable columns don't have a name attribute. So how do I get those? Do I have to use a template or something?
0
Vladimir Iliev
Telerik team
answered on 02 Jul 2014, 06:37 AM
Hi Stefan,

I'm little confused to the last answer - at the same time the other cell value is not updated in the dateItem and it's not editable? Could you please clarify more the exact scenario that you have as if given cell is not editable than it's value in the dataItem should be the correct one?

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
CS
Top achievements
Rank 2
answered on 02 Jul 2014, 06:42 AM
The difficulty is, if I want to compare a current input value with a value in a column that is not editable I can not use the name property for it since it does not have one. So in my case I could only search for something like [data-bind="value:variableName"] something like that.
0
Vladimir Iliev
Telerik team
answered on 02 Jul 2014, 07:47 AM
Hi Stefan,

As I already mention if the other field is not editable you should get it from the dataItem and compare it to the value in current input using your custom logic.

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
CS
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
CS
Top achievements
Rank 2
Share this question
or