Search code examples
jqgrid

jqGrid - Issue with editrules when dynamically changing editable property on column model


I am using inline row editing for a jqGrid.

I loop through each row and before calling editRow(), I set the editable property on the column model for certain rows as FALSE (making the column for some rows as non editable). This all works fine until I add editrules to the column model. I get a javascript error "a is undefined" when saving the rows.

Question - Is there a way to make a column non-editable for certain rows and for other rows have an edit rule defined?

Any inputs is greatly appreciated!


Solution

  • I was able to solve this by setting/resetting the editrules property on the colModel before calling saveRow() on each row. Below is the code snippet

    function updateEditRuleProp() {
        var qtyRule = {required:true, number:true, minValue:1};
        if (condition to disable editrules) { 
              qtyRule = null;
        }
        jQuery("#tableId").jqGrid('getColProp', 'yourColumName').editrules = qtyRule;
    }
    

    Here is the code that calls the above function

    var $this = jQuery("#tableId"), ids = $this.jqGrid('getDataIDs'), i, l = ids.length;
    for (i = 0; i < l; i++) {
            updateEditRuleProp();
            jQuery("#tableId").jqGrid('saveRow', ids[i]);
    }