Check documentation for the latest version of dhtmlxSuite Defining Grid Structure on Server Side DHTMLX Docs

Defining Grid Structure on Server Side

APPLICABLE TO: Grid

Starting from version 1.0, connectors can be used to define the header of Grid.

It can be done in 2 ways:

Automatic defining

In case of automatic defining, Grid will use names of a table's fields as labels for the columns.

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

If you want to apply an automatic server-side sorting and filtering for the specified columns, you should specify true inside of GridConfiguration:

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

Manual defining

In the manual mode the headers and their parameters are defined by php command. Names of commands mimic the names of the js commands with a 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");

Available commands

All commands below get as the input parameter an array of values or a comma-separated string, delimited by 'header delimiter' (default value - ',').

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

Header and footer

To attach a header to the grid you should use the attachHeader() method:

$config->attachHeader($values, $styles = null);

Parameters:

  • array or string of header names. In case of a string, the names are delimited by 'header delimiter' (default value -',')
  • array or string of header styles. In case of a string, the styles are delimited by 'header delimiter' (default value - ',')

To attach a footer to the grid you should use the attachFooter() method:

$config->attachFooter($values, $styles = null);

Parameters:

  • array or string of footer names. In case of a string, the names are delimited by 'header delimiter' (default value - ',')
  • array or string of footer styles. In case of a string, the styles are delimited by 'header delimiter' (default value - ',')

Header delimiter

The header delimeter sets a symbol or several symbols which will be used as a delimiter in string arguments.

$config->setHeaderDelimiter($headerDelimiter);

Related samples

Back to top