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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom Validation

Thread ID:

Created:

Updated:

Platform:

Replies:

143701 Apr 1,2019 02:17 PM UTC Apr 5,2019 07:15 AM UTC JavaScript - EJ 2 5
loading
Tags: Grid
Miguel Varela Rodriguez
Asked On April 1, 2019 02:17 PM UTC

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', 
                    textAlign:'Right',
                    visible:true,
                    type:'number',
                     format: '##.##',
                    //editType:'numericedit',
                    edit:{params:{decimals:2}},
                    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


Pavithra Subramaniyam [Syncfusion]
Replied On April 2, 2019 05:36 AM UTC

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. 
 
[index.js] 
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 
            }, 
          .   .  . 
        ], 
    }); 
    grid.appendTo('#Grid'); 
 
    function checkMaxHours(args){ 
          var row = grid.getRowObjectFromUID(ej.base.closest(args.element, '.e-row').getAttribute('data-uid')); 
          console.log(row.data); 
        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. 

Regards, 
Pavithra S. 


Miguel Varela Rodriguez
Replied On April 2, 2019 07:41 AM UTC

Thank you this was what i looked for.

Pavithra Subramaniyam [Syncfusion]
Replied On April 2, 2019 08:44 AM UTC

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.  
 
Regards, 
Pavithra S. 


Miguel Varela Rodriguez
Replied On April 3, 2019 01:16 PM UTC

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

Pavithra Subramaniyam [Syncfusion]
Replied On April 5, 2019 07:15 AM UTC

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. 
 
Regards, 
Pavithra S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon