Accessing row data in custom validator

Hi,

I'm trying to access other cell values in a custom validator.  I have been following this knowledge base doc: https://www.syncfusion.com/kb/7129/how-to-access-row-data-in-custom-validator.

I have not had any luck getting it to work.  "serializeAllArray()" only returns the data for the current cell.  I need to compare it to other cells in the same row.

Is it because my grid is in "Batch" edit mode? Am I missing something or done something wrong?  Below is my javascript:

$(function () {
        $.fn.serializeAllArray = function () {
            var data = $(this).serializeArray();//returns the form data

            $(':disabled[name]', this).each(function () {  // when I step through the javascript it never goes in here
                data.push({ name: this.name, value: $(this).val() });//push the disabled elements values also to the JSON array
            });

            return data;
        }
      
        $.validator.addMethod("intBetween", function (value, element, params) {

            var data = $(element.closest("form")[0].form).serializeAllArray();//holds the form data in name and value pair
            // data only contains name and value pair for current cell.  I need to get the entire row           

            // todo: validation

            return true;
        }, intBtErrMsg);
    });

Thanks,
Chris

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team July 26, 2018 12:53 PM UTC

Hi Chris, 

Thanks for contacting Syncfusion Support. 

We have checked your reported problem and this KB https://www.syncfusion.com/kb/7129/how-to-access-row-data-in-custom-validator only applicable for Normal Mode. We cannot get the row Data in batch EditMode. 

If you want to access the rowData, you can get corresponding index value from getIndexByRow from the edited cell and also get the data from getDataByIndex

Please refer to the code example:- 

$(function () { 
       $.validator.addMethod("customCompare", function (value, element, params) { 
            var gridObj = $(".e-grid").ejGrid("instance"); 
            var inx = gridObj.getIndexByRow($(this.currentForm).closest("tr")); 
            var data = gridObj.getDataByIndex(inx);  //you can get the row Data here 
            return element.value > params[0] && element.value < params[1]; 
        }, "Freight value must be between 0 and 1000"); 
 
        $.validator.addMethod("customRegex", function (value, element, params) { 
            if (element.value.length == params) 
                return true; 
            return false; 
        }, "Customer ID must be 5 characters"); 
    }); 


Please refer to API Link:- 

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

Regards, 
Farveen sulthana T 



Loader.
Up arrow icon