Is't possible to export the grid as pdf (standard mode) as xls (custom export) at the same time?
Thanks in advance
You can have
$e["on_export"] = array("custom_export", null, false);
$g->set_events($e);
And in callback, you can put xls only check.
function custom_export($param)
{
$sql = $param["sql"]; // the SQL statement for export
$grid = $param["grid"]; // the complete grid object reference
if ($grid->options["export"]["format"] == "xls")
{
// custom implementation
}
}
To enable both options in grid,
"export_excel"=>true, // export excel button
"export_pdf"=>true, // export pdf button
e.g.
$g->set_actions(array(
"add"=>false, // allow/disallow add
"edit"=>false, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export_excel"=>true, // export excel button
"export_pdf"=>true, // export pdf button
"export_csv"=>true, // export csv button
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
Following your suggestion you have to develop also all the custom code for exporting to PDF;
I was wondering if you could write custom code to export in EXCEL format and, at the same time, use the standard code for export in PDF format.
When you provide callback with only xls check, it will only do custom code for xls, and pdf will work as default.
Sorry but doesn't work.
This is the relevant code:
…
$grid["export"] = array("format"=>"xls", "filename"=>$GLOBALS['form']['customers'], "sheetname"=>$GLOBALS['form']['customers'], "heading"=>$GLOBALS['form']['customers'], "range" => "filtered");
…
$g->set_actions(array(
…
"export_excel"=>true,
"export_pdf"=>true,
…
$e["on_export"] = array("custom_export", null, false);
…
function custom_export($param) {
$sql = $param["sql"]; // the SQL statement for export
$grid = $param["grid"]; // the complete grid object reference
if ($grid->options["export"]["format"] == "xls") {
…
}
}
when I try to export PDF I obtain always an excel file.
Hello,
Don't specify format in this line. Refer demos/export/export-all.php
$grid["export"] = array("filename"=>$GLOBALS['form']['customers'], "sheetname"=>$GLOBALS['form']['customers'], "heading"=>$GLOBALS['form']['customers'], "range" => "filtered");
Second,
3rd argument will be true, as you want to continue pdf export as default.
$e["on_export"] = array("custom_export", null, true);
…
function custom_export($param) {
$sql = $param["sql"]; // the SQL statement for export
$grid = $param["grid"]; // the complete grid object reference
if ($grid->options["export"]["format"] == "xls") {
…
// also need to put die; after custom excel export.
}
}
Regards,
Errata corrige.
If I do as you suggested the script doesn't execute my custom export, because it doesn't find the variable $grid->options["export"]["format"] setted.
If I add the above variable then both Excel and Pdf export extract the same xls file !
Ok, you can try these conditions …
if ($_GET["export_type"] == "excel")
{
// your code
}
Now I have another problem.
With the my custom_export I obtained an Excel file with the only columns with '$col["export"] = true;'.
Instead if I try to export a PDF file, with the standard export, I obtain all the columns.
How do I do?
The $col["export"] = false; setting works to disable columns from export.
By default, all columns are exported.
Of course.
In a table I have 18 fields.
I defined $col["export"] = false; for 10 fields.
I use a custom export with a custom routine only for Excel files (with $_GET["export_type"] == "excel").
Well.
When I export Excel file I obtained the only columns with export = true, when I export a PDF file I obtain all the columns