jqgridjqgrid-formattermvcjqgrid

Pass RowData to Custom_func in Jqgrid


I have a jqgrid with certain columns. I am trying to call a custom_function to validate the cell value.

I am also getting a regular expression from the database into rowData, which I want to use to validate the cell value.

var ret = jQuery("#settingsListGrid").jqGrid('getRowData', id);
cm.editrules = {
    required: true, 
    custom: true, 
    custom_func: ValidateData, 
    custom_value:ret.RegX 
};

So I need to pass rowData to a custom function.

ValidateData = function (value, colname, customValue) {
    return customValue.test(value) ?
        [true] :
        [false, "Invalid Data"];
}

I want to pass the rowData using customValue

Please help?


Solution

  • The answer depend on the fork of jqGrid, which you use. I understand the problem which you wrote, but one have to change the code of jqGrid (the implementation of custom validation) to implement the requirement.

    I develop free jqGrid fork of jqGrid after Tony Tomov changed the license agreement of jqGrid, renamed his product in version 4.7.1 to Guriddo jqGrid JS (see the post) and made it commercial (see the prices here). After starting the development based on the last free 4.7 version I made a lot of changes and improvements in the code and have implemented many new features. The feature which you need is implemented starting with version 4.12.1 (see here). Thus you can easy solve your problem after updating to the current free jqGrid 4.13.2.

    The new feature works as following:

    editrules: {
        required: true, 
        custom: ValidateData, 
        custom_value: ret.RegX 
    }
    

    It's important that one should specify the custom validation function as the value of custom property instead of usage custom_func. It allows free jqGrid to hold compatibility to old versions (via custom: true and custom_func), but providing new parameters of the validation callback via function as the value of custom property.

    The new style ValidateData will look like

    var ValidateData = function (options) {
        return customValue.test(options.newValue) ?
            [true] :
            [false, "Invalid Data"];
    }
    

    with only one options parameter, which have many properties which you could use. Such style allows to provide many helpful information without the requirement to have a lot of unneeded parameters. Moreover the style of callback options allows to extend the options object in the future versions without breaking compatibility to previous versions.

    The options parameter have the following properties

    I hope that the large set of properties of options parameter allows you easy implement your requirements on any custom validation.