Live Examples
Example 13: AJAX-Enabled Inlined Editing
Inline editng works just like a spreadsheet. Set the first parameter in method set_inlineedit_enabled() to true to enable inline editing. When the second parameter is set to true, it turns the AJAX Auto-Save feature. The new value is automatically saved in database without clicking the Save button on the toolbar. The second parameter is default to true when omitted.
$dg = new C_DataGrid($hostName, $userName, $password, $dbName); $dg -> set_gridpath ("include/"); $dg -> set_sql ("SELECT * FROM Employees"); $dg -> set_sql_table ("Employees"); $dg -> set_sql_key ("EmployeeId"); // change column titles $dg -> set_col_title ("EmployeeId", "Employee ID"); $dg -> set_col_title ("LastName", "Last Name"); $dg -> set_col_title ("FirstName", "First Name"); // set background and mouse over color $dg -> set_alt_bgcolor ("#ffcc99, #ffccdd"); $dg -> set_onmouseover ("yellow"); // hide a column $dg -> set_col_hidden ("Notes"); // display URL as hyperlink $dg -> set_col_link ("ReportsTo", "/query.php?EmployeeId=", "EmployeeId", "target='_new'"); // set page size $dg -> set_page_size (20); // make the datagrid editable $dg -> set_allow_actions(true); // set data administrative level // "V" means View, "E" means Edit, and "D" means Delete. $dg -> set_action_type ("VE"); // view and edit only // make BirthDate and HomePhone read only $dg -> set_fields_readonly("LastName, HomePhone"); // sum up columns $dg -> set_col_sum_enabled(true); $dg -> set_col_sum ("Salary"); $dg -> set_col_sum ("Age"); // add Checkbox HTML control to status $dg -> add_control("Status", CHECKBOX, array("fulltime"=>"Full Time", "parttime"=>"Part Time", "contract"=>"Contract"), ","); // turn on inline-editing with Ajax enabled$dg -> set_inlineedit_enabled(true, true);$dg -> display();




