- Parameter(s):
- $col_name: Column name
- $ctrl_type: HTML control type. A list of valid controls are:
- text
- textarea
- select
- checkbox
- password
- button
- autocomplete – New!
For enum type, use select as edit type and pass hard coded key:value pair as 3rd parameter
- $keyvalue_pair: This parameter is only required when the $ctrl_type is type “select” or “checkbox”. It essentially represents list of value key pairs in the dropdown. e.g. “1:San Francisco;2:Boston;3:NYC”. It is ignored if the control type is not “select”.*
Hint: add “:;” (colon semicolon) to the front of the the key value pairs to add a blank dropdown option. Make sure there is no trailing semi-colon.v4.2 Update:
X
- $multiple: This parameter is only used when control type is “select”. It indicates whether multiple items can be selected in the list of options. The values are passed and stored as a comma delimited string. e.g. “1,2,3”. For single value “select”, this is not required.
- $dataUrl: If your lookup table has more than 100 elements (a hard limit set in function), it is recommended to use this parameter. This option is valid only for elements of type “autocomplete” and should be the URL to get the AJAX data for the select element. The data is obtained via an AJAX call and should be a valid HTML select element with the desired options <select><option value=’1′>One</option>…</select>. You can use option group. The AJAX request is called only once when the element is created. In the inline edit or the cell edit module it is called every time when you edit a new row or cell. In the form edit module only once.
- Description:
- Set control of a specific column used for grid editing. It displays HTML input tag of different type accordingly e.g. <input type=”text” />, <input type=”textarea” /><
- Remark:
- Text and textarea are set automatically based on the database access library ADOdb metatype as the default edit control. Users do not need to understand how ADOdb works since phpGrid took care all the plumbing work internally. Isn’t that nice?
- Example:
1 2 3 4 | $dg -> set_col_edittype("officeCode", "select", "1:San Francisco;2:Boston;3:NYC", false); $dg -> set_col_edittype("isActive", "checkbox", "1:0"); // bind dropdown menu to a lookup table $dg -> set_col_edittype("officeCode", "select", "Select officeCode,city from offices",false); |
An example that uses $dataUrl to filter potentially large sets of data in select options.
1 2 3 | $dg -> set_col_edittype("officeCode", "autocomplete", array('sql' => 'Select officeCode,city from offices150k', 'ajaxDataUrl' => 'sample-select-dataUrl.php'), false); |
An example of “sample-select-dataUrl.php”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | use phpCtrl\C_DataGrid; use phpCtrl\C_DataBase; require_once("../conf.php"); $db = new C_DataBase(PHPGRID_DB_HOSTNAME, PHPGRID_DB_USERNAME, PHPGRID_DB_PASSWORD, PHPGRID_DB_NAME, PHPGRID_DB_TYPE,PHPGRID_DB_CHARSET); $result = $db->select_limit("Select officeCode, city from offices150k WHERE city like '%". $_GET['q'] ."%'", 10, 0); $options = array(); while($row = $db->fetch_array_assoc($result)) { $options[] = (object)array('id'=>$row['officeCode'], 'text'=>$row['city']); } $select_options['results'] = $options; echo json_encode($select_options); |