We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom Validation

Hi Syncfusion Team,

i got a Data Grid and have set up some custom validation for a field. Now i need to check in this routine no just the value of the edited cell, instead i want to get the current Row ID of the Edited Row.

in the Args i just get data from the edit element.

Here the related code of the column:

                    field: 'partHours', 
                    headerText: 'Horas', 
                     format: '##.##',
                    validationRules:{required:true,minLength:[checkMaxHours,'Este campo es obligatorio']}

And then in the checkMaxHours function, how can i get the Row ID from the args send to function?

  function checkMaxHours(args){
          //Get row ID here
        return true;

greets from Spain, Miguel

5 Replies

PS Pavithra Subramaniyam Syncfusion Team April 2, 2019 12:36 AM

Hi Miguel, 

Thanks for contacting Syncfusion support. 
You can get the original grid row data inside the custom validation function by using the “getRowObjectFromUID” method which will provide the Row object. Please refer to the below code example and sample link for more information. 
var grid = new ej.grids.Grid({ 
        dataSource: window.orderDataSource, 
        editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal', newRowPosition:'Top' }, 
        allowPaging: true, 
        pageSettings: { pageCount: 5 }, 
        toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
        columns: [ 
                field: 'OrderID', isPrimaryKey: true, headerText: 'Order ID', textAlign: 'Right', 
                validationRules: { required: true, number: true }, width: 140 
                field: 'CustomerID', headerText: 'Customer ID', 
               validationRules:{required:true,minLength:[checkMaxHours,'Este campo es obligatorio']}, width: 100 
          .   .  . 
    function checkMaxHours(args){ 
          var row = grid.getRowObjectFromUID(ej.base.closest(args.element, '.e-row').getAttribute('data-uid')); 
        return true; 
Note     : If you want to get the values in edit form you need to get the value from the input elements. 

Please get back to us if you need any further assistance on this. 

Pavithra S. 

MV Miguel Varela Rodriguez April 2, 2019 02:41 AM

Thank you this was what i looked for.

PS Pavithra Subramaniyam Syncfusion Team April 2, 2019 03:44 AM

Hi Miguel, 
Thanks for the update. 
We are happy to hear that your requirement was achieved. 
Please contact us if you need any further assistance. As always, we will be happy to assist you.  
Pavithra S. 

MV Miguel Varela Rodriguez April 3, 2019 08:16 AM

Hi i have some issue with this.

When i enter to edit the row, on any field with a custom validation, it gets called twice the first  time.

any idea why or what produces this?

thank you

PS Pavithra Subramaniyam Syncfusion Team April 5, 2019 02:15 AM

Hi Miguel, 

Thanks for you update. 

In Grid We perform the cell validation for every time the cell is focusOut and while saving the value to the Grid row. So the customvalidation method triggered twice. This is the default behavior of the Grid, not an issue. 

Please get back to us if you need further assistance. 
Pavithra S. 

Live Chat Icon For mobile
Up arrow icon