DHTMLX Docs & Samples Explorer

Defining grid structure on server side

Starting from version 1.0 , connectors can be used to define header of grid, it can be done in automatic and detailed modes

Automatic mode

require("../../codebase/grid_connector.php");
$grid = new GridConnector($res);
 
$grid->set_config(new GridConfiguration());
 
$grid->render_table("grid50000","item_id","item_nm,item_cd");

Grid will use list of fields - as labels for the columns. It can be combined with short render_table form as

$grid->set_config(new GridConfiguration());
$grid->render_table("grid50000");

In such case grid headers will be created for all columns in the related table

If you want to have automatic server side sorting and filtering for all columns , you can use

$grid->set_config(new GridConfiguration(true));
$grid->render_table("grid50000","item_id","item_nm,item_cd");

Manual mode

In manual mode you need to define headers and their parameters by php command. Names of commands mimic names of js commands, with similar functionality.

$config = new GridConfiguration();
$config->setHeader(array("column 1","column 2"));
$config->setColTypes(array("ro","ed"));
 
$grid->set_config($config);
 
$grid->render_table("grid50000","item_id","item_nm,item_cd");
Commands which can be used

For all below commands, parameter is an array of values or comma separated string, delimited by headerDelimiter (default is ,).

// column labels
$config->setHeader($names);
// column types
$grid->setColTypes($typeStr);
// column IDs
$grid->setColIds($idsStr);
// column width, int values, will be processed as size in pixels
$grid->setInitWidths($widths);
// column width, int value, will be threated as size in percents
$grid->setInitWidthsP($widths);
// column align
$grid->setColAlign($alStr);
// column sorting type
$grid->setColSorting($sortStr);
// column color
$grid->setColColor($colorStr);
// visibility of column 
$grid->setColHidden($hidStr);

For setColHidden command values must be

  • true if column should be hidden
  • false otherwise
Headers and Footers
$grid->attachHeader($values, $styles = null);

The parameters of this method are:

  • array of header names or string of header names, delimited by headerDelimiter (default is ,)
  • array of header styles or string of header styles, delimited by headerDelimiter (default is ,)
$grid->attachFooter($values, $styles = null);

The parameters of this method are:

  • array of footer names or string of footer names, delimited by headerDelimiter (default is ,)
  • array of footer styles or string of footer styles, delimited by headerDelimiter (default is ,)
Setting delimiter

Sets symbol or several symbols which will be used as delimiter in string arguments.

$grid->setHeaderDelimiter($headerDelimiter);

Example

require_once("../config.php");
$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db);
 
require("../../codebase/grid_connector.php");
$grid = new GridConnector($res);
 
$config = new GridConfiguration();
 
	$config->setHeader("Item Name,Item CD");
	$config->attachHeader("Item Name Test,#rspan");
	$config->attachFooter("Item Name,Item CD", Array("background-color: #ff0000;", "background-color: #00ff00;"));
	$config->attachFooter("Item Name Test,#rspan", "background-color: #0000ff;color:white;");
	$config->setColIds("col1,col2");
	$config->setInitWidths('120,*');
	$config->setColSorting("connector,connector");
	$config->setColColor("null,#dddddd");
	$config->setColHidden("false,false");
	$config->setColTypes("ro,ed");
	$config->setColAlign('center,center');
 
$grid->set_config($config);
$config->render_table("grid50000","item_id","item_nm,item_cd");

This example initializes the following structure: