Live Examples
Example 14: Condition-Based Output
One handy feature that phpGrid offers is the condition-based output. Let's say, a boolean value stored in table is either 1 or 0. Often when display it needs to be translated too something more meaningful. Function set_col_txt() can be used in such situation. It overwrites text from the database based on conditions. For more information on how each parameter is used, please refer to the online document.
$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); // condition-based output$dg -> set_col_txt ("IsSeniorEmployee"," < 1", "YES", "NO",false);$dg -> display();




