export both the pdf and xls but xls in custom mode

Questionsexport both the pdf and xls but xls in custom mode
Massimo Gagliardi asked 6 years ago

Is't possible to export the grid as pdf (standard mode) as xls (custom export) at the same time?
Thanks in advance

13 Answers
Abu Ghufran answered 6 years ago

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)
)
);

Massimo Gagliardi answered 6 years ago

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.

Abu Ghufran answered 6 years ago

When you provide callback with only xls check, it will only do custom code for xls, and pdf will work as default.

Massimo Gagliardi answered 6 years ago

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.

Abu Ghufran answered 6 years ago

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,

Massimo Gagliardi answered 6 years ago

Perfect! It works all the wonder

Massimo Gagliardi answered 6 years ago

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 !

Abu Ghufran answered 6 years ago

Ok, you can try these conditions …

if ($_GET["export_type"] == "excel")
{
// your code
}

Massimo Gagliardi answered 6 years ago

Now it works
Thank you very much

Massimo Gagliardi answered 6 years ago

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?

Abu Ghufran answered 6 years ago

The $col["export"] = false; setting works to disable columns from export.
By default, all columns are exported.

Massimo Gagliardi answered 6 years ago

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

Massimo Gagliardi answered 6 years ago

Sorry Abu
it was a my error
Alright

Your Answer

14 + 10 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?