jqgrid custom_func validate existing row

621 views Asked by At

I dont know what's wrong with my coding?

colModel: [
                {
                    key: true, hidden: true, name: 'Id', index: 'Id', editable: true
                }, {
                    name: 'ProjectCode',
                    index: 'ProjectCode',
                    sorttype: "text",
                    edittype: "text",
                    editable: true,
                    editrules: {
                        required: true,
                        custom: true,
                        custom_func: function (value, colName) {
                            return validateDuplicateData(value, colName);
                        }
                    }
                }

Here is validateDuplicateData function :

 function validateDuplicateData(value, colName) {
        var allRowsInGrid = $('#jqgrid').jqGrid('getRowData');
        $.each(allRowsInGrid, function (k, v) {
            if (v.ProjectCode == value) {
                return [false, "Project code has been used. Please try using another code."];
            }
        });
    }

why the result always shows below :

MessageBox : "Custom function should return array!"

Please advice... Thank you..

1

There are 1 answers

0
user9500275 On

The function never returns true with array. It should return true at the end of function if, after looping, no duplicate data was found.