Live Examples

Example 16: Change Overall Look and Feel with Theme

You can easily change phpGrid's look and feel with method set_theme() with pre-defined or user-defined themes. The theme files are located in include/theme folder. Simply pass the name of the theme folder to change the overall look and feel. You can even define your own theme if you are comfortable with CSS.

$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);
 
// create master/detail tables
$dg -> set_masterdetail("SELECT * FROM Sales", 
                        "employeeId", 
                        " AND price > 100");
 
// display image
$dg -> set_col_img      ("PhotoPath", "", "width:50px;");
 
// change theme
$dg -> set_theme("Sweet");
  $dg -> display();