Check documentation for the latest version of dhtmlxSuite Data Export DHTMLX Docs

Data Export

APPLICABLE TO: Grid

External grid-to-pdf and grid-to-excel services allow converting grid's data to PDF or Excel format directly on the server side: from any table without actually rendering data in the grid. Shortly, you should perform the following steps:

Data preparation

Activating conversion service

  • pdf
$convert = new ConvertService("http://dhtmlxgrid.appspot.com/export/pdf");
  • excel
$convert = new ConvertService("http://dhtmlxgrid.appspot.com/export/excel");

Start exporting

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

Parameters:

  • (optional) name of the resulting file. The default value:data.pdf (data.xls)
  • (optional) the second parameter specifies the way of exporting the file:
    • true - as an inline content ( if browser has a related plugin - document will be opened automatically)
    • false - as an individual file. The default value - false.

The service automatically starts exporting data defined through GridConnector.

Samples

  • PDF
require("../../../codebase/grid_connector.php");
require("../../../codebase/convert.php"); 
 
//url to data conversion service
$convert = new ConvertService("http://dhtmlxgrid.appspot.com/export/pdf");
$convert->pdf(); //equal to calling pdf("data.pdf", false)
 
$grid = new GridConnector($res);
$grid->set_config(new GridConfiguration()); //mandatory 
$grid->render_table("grid50");      //a table's name and an optional list of fields
  • Excel
require_once("../../config.php");
$res= new PDO("mysql:dbname=$mysql_db;host=$mysql_server",$mysql_user,$mysql_pass);
 
require("../../../codebase/grid_connector.php");
require("../../../codebase/convert.php");
 
//url to data conversion service
$convert = new ConvertService("http://dhtmlxgrid.appspot.com/export/excel");
$convert->excel(); //equal to calling excel("data.xls", false)
 
$grid = new GridConnector($res);
$grid->set_config(new GridConfiguration()); //mandatory 
$grid->render_table("grid50");         //a table's name and an optional list of fields

Useful tips

  • In case of the dynamic Smart Rendering you can't use export from the client side and need to define header's data on the server side. See the details here.
  • For correct work of the render_sql method you should use the full header initialization (not empty GridConfiguration() call). Otherwise, the component will try to fetch the grid's structure from DB that is unallowable for the render_sql method.
Back to top