Pay attention to the fact that dhtmlxGrid doesn't provide full support for data export in the smart rendering or paging modes and exports just the data which is already rendered on the client (not all the data).
The latest Export packages for installation can be found here:
To export data from dhtmlxGrid into a pdf document:
1) Download and unpack the appropriate Export package to the root level of your web server to the folder codebase (you don't need to install anything, just unpack).
2) Call the method toPDF(path). The method takes as a parameter the path to the generate.php file resided in the Export package.
For example, if you add a button by clicking on which dhtmlxGrid will start exporting, your code can be similar to this one:
// DHTMLX Suite is used
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css">
<script src="codebase/dhtmlx.js"></script>
<input type="button" value="Get as PDF"
onclick="mygrid.toPDF('codebase/grid-pdf-php/generate.php');">
<div id="gridbox" style="width:399px;height:270px;"></div>
<script> mygrid = new dhtmlXGridObject('gridbox');
...
</script>
The toPDF() method takes the second (optional) parameter that can be used to control the color map of the resulting PDF document.
The toPDF() method takes the third and the fourth (optional) parameters that can be used to set custom header (footer) images for the grid.
To add a header image to the grid:
mygrid.toPDF('codebase/grid-pdf-php/generate.php','color',true);
To add a footer image to the grid:
mygrid.toPDF('codebase/grid-pdf-php/generate.php','color',false,true);
The latest packages for installation can be found here:
To export data from dhtmxlGrid into an Excel document:
1) Download and unpack the appropriate Export package to the root level of your web server to the folder codebase (you don't need to install anything, just unpack).
2) Call the method toExcel(path). The method takes as a parameter the path to the generate.php file resided in the Export package.
For example, if you add a button by clicking on which dhtmlxGrid will start exporting, your code can be similar to this one:
// DHTMLX Suite is used
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css">
<script src="codebase/dhtmlx.js"></script>
<input type="button" value="Get as Excel"
onclick="mygrid.toExcel('codebase/grid-excel-php/generate.php');">
<div id="gridbox" style="width:399px;height:270px;"></div>
<script> mygrid = new dhtmlXGridObject('gridbox');
...
</script>
You can define what dhtmlxGrid will look like in a PDF or Excel document after it is exported, configuring the available options in the server-side code:
If any error occurs during data exporting and the result output is failed, a log file named as 'error_report_xxxx.xml' is automatically created in the grid-pdf-php (grid-excel-php) folder .
If output isn't failed, but still there are some problems, you can edit the generate.php and change the value of the debug variable to provoke generating of another log file named as 'debug_xxxxx.xml' :
$debug = false;
//change to
$debug = true;
In order not to download the Export package you may use online export services and call the toPDF() and toExcel() methods as:
// exporting to PDF by using the online export service
mygrid.toPDF("https://export.dhtmlx.com/grid5/pdf/");
// exporting to Excel by using the online export service
mygrid.toExcel("https://export.dhtmlx.com/grid5/excel/");
Back to top