Data export
APPLICABLE TO: grid
External grid-to-pdf and grid-to-excel services allow to convert grid's data to PDF or Excel format directly on server-side: from any table without actually rendering data in the grid. Shortly, you should perform the following steps:
data preparation
- data to export is defined by render_table() or render_sql() method.
- to define grid structure (header, footer etc.) on server-side, see chapter ''.
activation conversion service
- pdf
$convert = new ConvertService("http://dhtmlx.com/docs/products/devExchange/samples/grid2pdf_02/server/generate.php");
- excel
$convert = new ConvertService("http://dhtmlx.com/docs/products/devExchange/samples/grid2excel_02/server/generate.php");
start exporting
- pdf
$convert->pdf("some.pdf",false);
- excel
$convert->excel("some.xls",false);
Parameters:- (optional) name of result file. The default value - data.pdf (data.xls)
- (optional) the second parameter specifies how file will be exported:
- true - as inline content ( if browser has related plugin - document will be opened automatically)
- false - as individual file.
The default value - false.
Service automatically start to export data defined through GridConnector.
samples
- pdf
require("../../../codebase/grid_connector.php"); require("../../../codebase/convert.php"); //url to data conversion service $convert = new ConvertService("http://dhtmlx.com/docs/products/devExchange/samples/grid2pdf_02/server/generate.php"); $convert->pdf(); //equal to calling pdf("data.pdf", false) $grid = new GridConnector($res); $grid->set_config(new GridConfiguration()); //mandatory $grid->render_table("grid50"); //table name and optional list of fields
- Excel
require_once("../../config.php"); $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_select_db($mysql_db); require("../../../codebase/grid_connector.php"); require("../../../codebase/convert.php"); //url to data conversion service $convert = new ConvertService("http://dhtmlx.com/docs/products/devExchange/samples/grid2excel_02/server/generate.php"); $convert->excel(); //equal to calling excel("data.xls", false) $grid = new GridConnector($res); $grid->set_config(new GridConfiguration()); //mandatory $grid->render_table("grid50"); //table name and optional list of fields
useful tips
- In case of dynamic Smart Rendering you can't use export from client-side and need to define header's data on server-side. See details here.
- in order to the render_sql method works correctly, you should use full header initialization ( not empty GridConfiguration() call). Otherwise, the component will try to fetch grid's structure directly from DB that is unallowable for the render_sql method.