Check documentation for the latest version of dhtmlxSuite Grid Specific HowTos DHTMLX Docs

Grid Specific HowTos

How can I define grid structure on the server side?

To define grid structure on the server side you can use one of the two modes:

  • automatic
  • manual

In both modes you should use the set_config() method where GridConfiguration object must be specified as the input parameter.

In automatic mode grid will use the names of a table's fields as the labels for the columns.

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

In manual mode the structure is defined by php command. The names of commands mimic the names of 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");

For more information on the topics covered here, see the 'Defining grid structure on server side' guide.

How can I export grid's data from server to Excel file?

To export data to Excel file you should:

1) Include one additional file

require("../../../codebase/convert.php");

2) Activate the conversion service

$convert = new ConvertService(
"http://dhtmlx.com/docs/products/devExchange/samples/grid2excel_02/server/generate.php"
);

3) Start exporting

$convert->excel("some.xls",false);

Both method's parameters are optional. The first parameter is the name of an output file. The second parameter specifies how the file will be exported: true - as an inline content, false - as an individual file.

After you've called the method excel(), the service automatically starts exporting the data defined through GridConnector.

For more information on this topic see 'Data export' guide.

How can I export grid's data from server to pdf file?

To export data to pdf file you should:

1) Include one additional file

require("../../../codebase/convert.php");

2) Activate the conversion service

$convert = new ConvertService(
"http://dhtmlx.com/docs/products/devExchange/samples/grid2pdf_02/server/generate.php
");

3) Start exporting

$convert->pdf("some.pdf",false);

Both method's parameters are optional. The first parameter is the name of an output file. The second parameter specifies how the file will be exported: true - as an inline content, false - as an individual file.

After you call the method pdf(), the service automatically starts exporting the data defined through GridConnector.

For more information on this topic see 'Data export' guide.

How can I populate select/combo columns with data?

To define options of select/combo columns you have 2 ways:

1) to load data from the same table the grid is populated with data from

// value  label
$grid->set_options("item_nm",array("1" => "one", "2" => "two","3" => "three")); 
$grid->render_table("grid50","item_id","item_nm,item_cd");

2) to load data from another table

$options = new OptionsConnector($res, "MySQL");
$options->render_table("countries","country_id","country_id(value),country_name(label)");
$grid->set_options("item_nm",$options);
 
$grid->render_table("grid50","item_id","item_nm,item_cd");

For more information oN this topic see 'Select/combobox columns in grid' article.

How can I load data from a table that doesn't contain the identity field?

By using KeyGridConnector instead of GridConnector you can load data from a table without the identity field. In this case any data field will serve as the identity one.

$grid = new KeyGridConnector($res);
$grid->render_table("mytable","name","name,address,phone");

For more details see 'KeyGridConnector' guide.

How can I set a custom style for a row or a cell?

dhtmlxConnector contains a bit of methods that allow setting the appearance of a grid.

These methods can be divided into 2 groups:

for a cell customization:

for a row customization:

function color_rows($row){
    if ($row->get_index()%2)
    $row->set_row_color("red");
}
 
$grid = new GridConnector($res);
$grid->event->attach("beforeRender","color_rows");
$grid->render_table("records","item_id","item_nm,item_cd");

Tips:

  • to overwrite the background you should use the 'background' attribute, not the 'background-color' one.
  • skin's css can overwrite a number of css attributes. To avoid it, use the !important flag.
$row->set_row_attribute("class","backgroundclass");


.backrgroundclass{
   background:red !important;
}
Back to top