Skip to content

editable property of colModel as function

colinmacleod edited this page Mar 4, 2018 · 8 revisions

To allow editing in jqGrid, specify the editable property in colModel for the corresponding columns. Prior to jQGrid 4.8, the allowed values for editable were true or false (the default value). Sometimes, you need to allow editing dependent on other conditions. Free jqGrid 4.8 provides supports callback functions as the value of editable property.

For example, to allow changes in an order till the order is processed and the goods are sent, imagine a grid with columns sent (boolean) and ship_via (string delivery method). With local data, the definition of the editable property in free jqGrid 4.8 could be:

    {
        name: "ship_via",
        editable: function (options) {
            var item = $(this).jqGrid("getLocalRow", options.rowid);
            return !item.closed;
        },
        edittype: "select",
        editoptions: { value: "FE:FedEx;TN:TNT;DH:DHL", defaultValue: "DH" }
    }

If not using local data, use getRowData or getCell instead of getLocalRow.

The options parameter of editable contains the following properties:

  • rowid the id of the row to restrict editing, set to "_empty" for an Add form.
  • iRow - the index of the row, set to false for an Add form.
  • mode - "cell" for cell editing, "addForm" or "editForm" for form editing and "add" or "edit" for inline editing.

The callback function editable can return values other than true and false in the case of form editing (Add/Edit dialog). All editable columns will be inserted in the form, but hidden: true columns will be inserted hidden. As a result, jqGrid won't allow the user to edit the values, but the values will be sent to the server on form submit. To enforce this, the dynamic èditable function should return the "hidden" string. Because string values returned from the editable callback only apply to form editing, it's recommended to test the mode property of options for "addForm" or "editForm" values. The following string values are supported as return values:

  • "hidden" - denotes a hidden row with information about the column in the Add/Edit form. The information will be sent to the server on form submit, but will be hidden and the user unable to edit it.
  • "disabled" - denotes row data for the column to display disabled and readonly. Using this value one can, for example, show id information in an Edit form, but not allow editing of the data and to display a standard editable field in an Add form.
  • "readonly" - special value to set the readonly property of an input text field to true.

Edit:

this article suggests the "readonly" value cannot be used in inline edit. Actually "readonly" can be used in inline edit also: it works as expected in all edit modes by making the column read only. There is no need to check edit mode to make column read only.