KoolReport's Forum

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

Print, and PDF, CSV, Excel for DataTables with Details, or Group by #3075

Open iWorQ Systems opened this topic on on Jun 12, 2023 - 1 comments

iWorQ Systems commented on Jun 12, 2023

I am trying to use the Buttons listed above to export my Datatables that have a row Detail, or row group, and both are printing them as just columns. I was just wondering if there was any way to print them so they look like they do in the report. Here is the code and images for both:

Row Detail:

Report:

PDF:

Code:

DataTables::create([
                "name" => "rowDetailTable",
                "dataStore" => $this->dataStore("result"),
                "plugins" => ["Buttons", "FixedColumns", "FixedHeader", "KeyTable", "Responsive", "RowReorder", "Scroller", "SearchPanes"],
                "options" => [
                    "dom" => 'Blfrtip',
                    "buttons" => [
                        [
                            "title" => $title,
                            "extend" => 'pdfHtml5',
                            "orientation" => "landscape",
                            "pageSize" => "A5",
                        ],
                        "copy",
                        [
                            "title" => $title,
                            "extend" => 'csvHtml5',
                        ],
                        [
                            "title" => $title,
                            "extend" => 'excelHtml5',
                        ],
                        "print",
                    ],
                    "searching" => true,
                    "paging" => true,
                    
                    "order"=>array(
                        array(1,"asc")
                    )
                ],
                "cssClass" => [
                    "table" => "table table-bordered table-striped table-hover"
                ],
                "columns"=>$columns,
                "rowDetailData" => function($row) {
                    $noteDetail = $this->dataStore("noteDetails")->filter("instance_id", '=', $row['identifier']);
                    $this->params['detailCount'] +=1;
                    $html = "";
                    if(!$noteDetail->isEmpty()){
                        array_push($this->params['detailCountArray'], $this->params['detailCount']);
                        $html .= " <h4 class='underlineBold'> Notes </h4>" . Table::create(array(
                            "dataSource"=>$this->dataStore("noteDetails")->filter("instance_id", '=', $row['identifier'],),
                            "cssClass" => [
                                "table" => "tablewidth table-bordered table-striped table-hover"
                            ],
                            "excludedColumns"=>["instance_id"]
                        ), true);
                    } else{
                        return false;
                    } 
                    return $html;
                   
                },
            ]);

Row Group:

Report:

PDF:

Code:

DataTables::create([
                "dataStore" => $this->dataStore("result"),
                "plugins" => ["Buttons", "FixedColumns", "FixedHeader", "KeyTable", "Responsive", "RowReorder", "Scroller", "SearchPanes"],
                "options" => [
                    "dom" => 'Blfrtip',
                    "buttons" => [
                        [
                            "title" => $title,
                            "extend" => 'pdfHtml5',
                            "orientation" => "landscape",
                            "pageSize" => "A5",
                        ],
                        "copy",
                        [
                            "title" => $title,
                            "extend" => 'csvHtml5',
                        ],
                        [
                            "title" => $title,
                            "extend" => 'excelHtml5',
                        ],
                        "print"
                    ],
                    "searching" => true,
                    "paging" => true,
                ],
                "clientRowGroup" => [
                    "groupby" => [
                        "direction" => 'asc',
                        "top" => "<td colspan='999'>{expandCollapseIcon} ".$groupbyTitle.": {groupby}</td>",
                    ],
                ],
                "cssClass" => [
                    "table" => "table table-bordered table-striped table-hover"
                ],
                "columns"=>$columns,
            ]);

I really just want to see if I can print them as they look like on the table themselves. or if I will have to do custom printing options instead.

Sebastian Morales commented on Jun 13, 2023

If you want exact export, DataTable's client-sice export using Buttons plugin is not always the suitable solution. Instead use our server-side export Export and Excel packages.

For PDF, Export package can render DataTables with either rowDetail or rowgroup enabled. For Excel, excel's Table widget also has rowgroup property:

Excel's Table's rowgroup property

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
help needed

DataGrid