Sometimes we don’t want certain fields to be editable, then we can use set_col_readonly() method.
Note that you can set more than one columns to be read only using this method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | use phpCtrl\C_DataGrid; require_once("/file/path/to/conf.php"); $dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", "Orders"); // change column titles $dg -> set_col_title("orderNumber", "Order No."); $dg -> set_col_title("orderDate", "Order Date"); $dg -> set_col_title("shippedDate", "Shipped Date"); $dg -> set_col_title("customerNumber", "Customer No."); // enable edit $dg ->enable_edit("INLINE", "CRUD"); // hide a column $dg -> set_col_hidden("requiredDate"); // read only columns, one or more columns delimited by comma $dg -> set_col_readonly("orderDate, customerNumber"); $dg -> display(); |
To allow add for read-only field when adding new records, use “jqGridAddEditAfterShowForm” event, and conditionally remove the “disabled” attribute based on operand, which is either “edit” or “add”.
1 2 3 4 5 6 | $dg -> add_event('jqGridAddEditAfterShowForm', 'function(e, form, oper){ if (oper == "add") { $("#COLUMN_NAME").removeAttr("disabled"); } }'); |
Click on row to see the fields that are set to read-only.