DHTMLX Docs & Samples Explorer

Component-specific how-tos (grid)

How can I define grid structure on server-side?

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

  • automatic
  • manual

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

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

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

In manual mode, structure is defined 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");

For more information of the topics covered here, see '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 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 a name of output file. The second parameter specifies how file will be exported: true - as inline content, false - as individual file.

After you call the method excel(), service automatically will start to export data defined through GridConnector.

For more information of 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 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 a name of output file. The second parameter specifies how file will be exported: true - as inline content, false - as individual file.

After you call the method pdf(), service automatically will start to export data defined through GridConnector.

For more information of this topic, see 'Data export' guide.

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

Using KeyGridConnector instead of GridConnector, you can load data from a table without identity field. In this case, any data field will serve as identity.

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

For more details, see 'KeyGridConnector' guide.

How can I set a certain color for a row?

Using set_row_color() method you can set a certain color for a row.

$dataItem->set_row_color($color)

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

Using methods set_cell_style() and set_row_style you can set some style for a row or cell.

$dataItem->set_row_style($style);
//
$dataItem->set_cell_style($style);

where $style specifies HTML style attributes.