KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Export subreport to pdf with parameters #2803

Open Andrew Guattery opened this topic on on Aug 21, 2022 - 3 comments

Andrew Guattery commented on Aug 21, 2022

I have a report with a subreport. The subreport is loaded with parameters from the main report. This is working fine. Now I would like to export the subreport to pdf. I seem to have it set up ok so that the button i click to export downloads a pdf that has the header from the subreport but no data. Im sure this is due to no parametersbeing sent back to the subreport.php before subreportpdf.view.php is loaded. Can we pass parameters to export.php and have it reload or update the subreport for export? If so, how?

Sebastian Morales commented on Aug 22, 2022

You can attach parameters to your subreport's client update function like this:

<script>
    function updateCustomers() {
                subReport.update('Customers',{ // "Customers" is the subreport's name
                    country:$('#country').val(),
                });
    }
</script>

Then in your report setup you could get "country" via $_POST["country"] or $this->params["country"] if you use trait inputs\Bindable and inputs\POSTBinding for param "country". Let us know if you have any question. Tks,

Andrew Guattery commented on Aug 22, 2022

Sebastian, Ok, I managed to get this working (sort of) by doing the following: The button for the PDF download is not inside a form; I created a function which builds up a GET string and then sets the window.location.href to export.php. in export.php I call the report like this:

$report = new Payroll(array(
    "store"=>$_GET['store'],
    "employees"=>$_GET['employees'],
    "mindt"=>$_GET['mindt'],
    "maxdt"=>$_GET['maxdt']
));

and then to export:

$report->run()
->export('PayrollRptPdf',array(

    "store"=>$_GET['store'],
    "employees"=>$_GET['employees'],
    "mindt"=>$_GET['mindt'],
    "maxdt"=>$_GET['maxdt']
))
->pdf(array(
    "format"=>"letter",
    "orientation"=>"portrait"
))
->toBrowser($filename);

This is now showing the datatable with data in pdf form. Almost done! Now the datatable in the export pdf has data BUT... the datatable is not rendering the grouping and rows at all:

DataTables::create(array(
       "name" => "payrollbyemp",
          "dataStore"=>$this->dataStore("paybyp"), 
           "options"=>array(
           'autoWidth' => false,
            array(1,"asc"), //Sort by first column desc
            array(2,"asc"), //Sort by second column asc

   "method"=>"post",
    "columns"=> [
    "STR_ID"=>[
    "label"=>"Store",
    "format"=>"string"],
    "USR_ID"=>[
    "label"=>"User ID",
    ],
    "HAS_COMMNTS"=>[
    "label"=>"comments",
    'formatValue'=>function($value, $row, $cKey) {
        if($row["IsHoliday"] == 1){
        return $row["HolidayText"];
        }else{
        return $row["HAS_COMMNTS"];
        }
        }
    ],
    "PERIOD_DT"=>[
    "label"=>"Clock Date",
    "displayFormat"=>"m-d-Y"
     ],
    "CLOCK_IN"=>[   
    "label"=>"Clock In"],
    "CLOCK_OUT"=>[
    "label"=>"Clock Out"],
    "PD_HRS"=>[
    "label"=>"Paid Hours"],
    "TTL"=>[
    "label"=>"Total Hours",
    "formatValue" => function($value, $row, $cKey) {
    return max(number_format($value, 2, '.', ' '),0);
    },
    ],
    "USRNAME"=>[
    "label"=>"user",
    "visible"=>false
    ],
    "PD_TIM"=>[
    "label"=>"user",
    "visible"=>false
    ],
    ],

    "clientRowGroup" => [
        "USRNAME" => [
 
            'calculate' => [
                'pdhrsAmount' => [
                    'sum', //'sum', 'count', 'avg', 'min', 'max'
                    'PD_HRS',

                ],
                'totalhoursAmount' => [
                'sum',
                'TTL',
                "format" => "function(value) {return value.toFixed(2);}",
                
                ],
            ],
                      "top"=>"",
           "bottom"=>"<td></td><td></td><td></td><td></td><td colspan=\"2\"><b>Total for user {USRNAME}</b></td><td><b>{pdhrsAmount}</b></td><td><b>{totalhoursAmount}</b></td>"
           ],
           ],
           

            "cssClass"=>array(
        "table"=>"table table-striped table-bordered",
        "tr"=>function($row,$columnName)
            {
             
                    //Base on $row["{column_name}"], you return correct css class to add css class
                    if($row["HAS_COMMNTS"]=="*"){ return "blueCss";}
                    if($row["PTO"]=="*"){ return "yellowCss";}
                    if($row["IsHoliday"]==1){ return "orangeCss";}
            }
    )//end css class
        
    ));//End Table::create

Any idea why the grouping/sum is not working?

Sebastian Morales commented on Aug 24, 2022

I can confirm the Export package doesn't support DataTables' client row group feature because its PDF rendering engine is incompatible with DataTables' row group plugin. You have two options here:

1 . Use Table widget with its server-based row group: https://www.koolreport.com/docs/koolphp/table/#row-group

2 . Use CloudExport package which does support DataTables' client row groupin: https://www.koolreport.com/docs/cloudexport/chromeheadlessio/

Let us know if you have any question. Tks,

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None