KoolReport's Forum

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

Multiple tables under one data table #2702

Open iWorQ Systems opened this topic on on May 31, 2022 - 6 comments

iWorQ Systems commented on May 31, 2022

This may seem like an odd request, but I was wondering if there was anyway to either have multiple tables under thae same data table, or be able to use one export button for multiple data tables?

KoolReport commented on Jun 1, 2022

If you have multiple tables in one report, then exporting the report will export all tables. Please let me know if I did not understand your question correctly.

iWorQ Systems commented on Jun 1, 2022

I am using multiple data tables. so each one has its own export button with it, and I was wondering if there was a way to get it so when I click that export button it would export all the data tables. I will show you a few pictures as reference.

Does that make sense? Am I just going to have to have a export all button and export them not using those built in buttons?

Sebastian Morales commented on Jun 2, 2022

Hi Ted, if you use DataTables' Buttons plugin for export, which is a client-side solution, you can only export one table data at a time. Using a separate Export button to call server-side exporting you can export as many tables as you want. Pls check our documentation and online examples:

https://www.koolreport.com/docs/excel/export_to_excel/

https://www.koolreport.com/examples/reports/excel/excel_template/

https://www.koolreport.com/examples/reports/excel/table/

If you have any question let us know. Tks,

iWorQ Systems commented on Jun 2, 2022

One last question for you. I got those working, but we are having a problem on the exportToCSV function.

The tables are loading in fine, but the problem is that we have footer on those tables that we would also like to get on there. The way we did that on the excel download was to just to add another row that had that information on it, but we cannot seem to do that on the CSV download. is there a way to add a custom row to a download CSV?

iWorQ Systems commented on Jun 2, 2022

here is my code for the CSV download

    array(
        "dataStores" => array(
            "workOrder" => [
                "separator" => ",", // default separator = "," i.e. comma
                "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                "enclosure" => ["(", ")"], // all enclosure property could be a 2 element array
                "typeEnclosures" => [
                    "string" => "\"", // default string enclosure is general enclosure
                    "date" => "\"", // default date enclosure is general enclosure
                    "datetime" => "\"", // default datetime enclosure is general enclosure
                    "number" => "", // default number enclosure = "" i.e. empty string
                    "boolean" => "", // default boolean enclosure = "" i.e. empty string
                ],
                'nullEnclosure' => "", // default = "" i.e empty string
                'nullString' => "NULL", // default = false i.e empty string for null value
                'useColumnFormat' => 1, // default = 1, set = 0 to increase export speed
                'useEnclosureEscape' => 1, // default = 1, set = 0 to increase export speed
                'useTypeEnclosure' => 1, // default = 1, set = 0 to increase export speed     
                "escape" => "\\", // if escape is empty/undefined, double enclosures will be used
                "eol" => "\n", // define End of line character, default eol is "\n"
                "columns" => array(
                    "Work Order Number",
                    "Work Order Date",
                    "Project Name",
                    "Road Name",
                    "Work Type",
                ),
                'useCustomColumnEnclosure' => 0, // default = 0
                'useCustomColumnNullString' => 0, // default = 0
                'useCustomColumnEnclosureEscape' => 0, // default = 0             
            ],
            "labor" => [
                "separator" => ",", // default separator = "," i.e. comma
                "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                "enclosure" => ["(", ")"], // all enclosure property could be a 2 element array
                "typeEnclosures" => [
                    "string" => "\"", // default string enclosure is general enclosure
                    "date" => "\"", // default date enclosure is general enclosure
                    "datetime" => "\"", // default datetime enclosure is general enclosure
                    "number" => "", // default number enclosure = "" i.e. empty string
                    "boolean" => "", // default boolean enclosure = "" i.e. empty string
                ],
                'nullEnclosure' => "", // default = "" i.e empty string
                'nullString' => "NULL", // default = false i.e empty string for null value
                'useColumnFormat' => 1, // default = 1, set = 0 to increase export speed
                'useEnclosureEscape' => 1, // default = 1, set = 0 to increase export speed
                'useTypeEnclosure' => 1, // default = 1, set = 0 to increase export speed     
                "escape" => "\\", // if escape is empty/undefined, double enclosures will be used
                "eol" => "\n", // define End of line character, default eol is "\n"
                "columns" => array(
                    "Employee",
                    "Hours",
                    "Hourly Rate",
                    "Total Cost",
                ),
                'useCustomColumnEnclosure' => 0, // default = 0
                'useCustomColumnNullString' => 0, // default = 0
                'useCustomColumnEnclosureEscape' => 0, // default = 0             
            ],
            
            "equipment" => [
                "separator" => ",", // default separator = "," i.e. comma
                "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                "enclosure" => ["(", ")"], // all enclosure property could be a 2 element array
                "typeEnclosures" => [
                    "string" => "\"", // default string enclosure is general enclosure
                    "date" => "\"", // default date enclosure is general enclosure
                    "datetime" => "\"", // default datetime enclosure is general enclosure
                    "number" => "", // default number enclosure = "" i.e. empty string
                    "boolean" => "", // default boolean enclosure = "" i.e. empty string
                ],
                'nullEnclosure' => "", // default = "" i.e empty string
                'nullString' => "NULL", // default = false i.e empty string for null value
                'useColumnFormat' => 1, // default = 1, set = 0 to increase export speed
                'useEnclosureEscape' => 1, // default = 1, set = 0 to increase export speed
                'useTypeEnclosure' => 1, // default = 1, set = 0 to increase export speed     
                "escape" => "\\", // if escape is empty/undefined, double enclosures will be used
                "eol" => "\n", // define End of line character, default eol is "\n"
                "columns" => array(
                    "Equipment",
                    "Unit Cost",
                    "Hours",
                    "Total Cost",
                ),
                'useCustomColumnEnclosure' => 0, // default = 0
                'useCustomColumnNullString' => 0, // default = 0
                'useCustomColumnEnclosureEscape' => 0, // default = 0             
            ],
            "material" => [
                "separator" => ",", // default separator = "," i.e. comma
                "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                "enclosure" => ["(", ")"], // all enclosure property could be a 2 element array
                "typeEnclosures" => [
                    "string" => "\"", // default string enclosure is general enclosure
                    "date" => "\"", // default date enclosure is general enclosure
                    "datetime" => "\"", // default datetime enclosure is general enclosure
                    "number" => "", // default number enclosure = "" i.e. empty string
                    "boolean" => "", // default boolean enclosure = "" i.e. empty string
                ],
                'nullEnclosure' => "", // default = "" i.e empty string
                'nullString' => "NULL", // default = false i.e empty string for null value
                'useColumnFormat' => 1, // default = 1, set = 0 to increase export speed
                'useEnclosureEscape' => 1, // default = 1, set = 0 to increase export speed
                'useTypeEnclosure' => 1, // default = 1, set = 0 to increase export speed     
                "escape" => "\\", // if escape is empty/undefined, double enclosures will be used
                "eol" => "\n", // define End of line character, default eol is "\n"
                "columns" => array(
                    "Material",
                    "Unit Cost",
                    "Amount",
                    "Total Cost",
                ),
                'useCustomColumnEnclosure' => 0, // default = 0
                'useCustomColumnNullString' => 0, // default = 0
                'useCustomColumnEnclosureEscape' => 0, // default = 0             
            ],
            "inventory" => [
                "separator" => ",", // default separator = "," i.e. comma
                "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                "enclosure" => ["(", ")"], // all enclosure property could be a 2 element array
                "typeEnclosures" => [
                    "string" => "\"", // default string enclosure is general enclosure
                    "date" => "\"", // default date enclosure is general enclosure
                    "datetime" => "\"", // default datetime enclosure is general enclosure
                    "number" => "", // default number enclosure = "" i.e. empty string
                    "boolean" => "", // default boolean enclosure = "" i.e. empty string
                ],
                'nullEnclosure' => "", // default = "" i.e empty string
                'nullString' => "NULL", // default = false i.e empty string for null value
                'useColumnFormat' => 1, // default = 1, set = 0 to increase export speed
                'useEnclosureEscape' => 1, // default = 1, set = 0 to increase export speed
                'useTypeEnclosure' => 1, // default = 1, set = 0 to increase export speed     
                "escape" => "\\", // if escape is empty/undefined, double enclosures will be used
                "eol" => "\n", // define End of line character, default eol is "\n"
                "columns" => array(
                    "Inventory",
                    "Quantity",
                    "Total Cost",
                ),
                'useCustomColumnEnclosure' => 0, // default = 0
                'useCustomColumnNullString' => 0, // default = 0
                'useCustomColumnEnclosureEscape' => 0, // default = 0             
            ],
            "purchaseOrders" => [
                "separator" => ",", // default separator = "," i.e. comma
                "enclosure" => "\"", // default general enclosure = "" i.e. empty string
                "enclosure" => ["(", ")"], // all enclosure property could be a 2 element array
                "typeEnclosures" => [
                    "string" => "\"", // default string enclosure is general enclosure
                    "date" => "\"", // default date enclosure is general enclosure
                    "datetime" => "\"", // default datetime enclosure is general enclosure
                    "number" => "", // default number enclosure = "" i.e. empty string
                    "boolean" => "", // default boolean enclosure = "" i.e. empty string
                ],
                'nullEnclosure' => "", // default = "" i.e empty string
                'nullString' => "NULL", // default = false i.e empty string for null value
                'useColumnFormat' => 1, // default = 1, set = 0 to increase export speed
                'useEnclosureEscape' => 1, // default = 1, set = 0 to increase export speed
                'useTypeEnclosure' => 1, // default = 1, set = 0 to increase export speed     
                "escape" => "\\", // if escape is empty/undefined, double enclosures will be used
                "eol" => "\n", // define End of line character, default eol is "\n"
                "columns" => array(
                    "Vendor",
                    "Date",
                    "Description",
                    "Invoice Number",
                    "Total Cost",
                ),
                'useCustomColumnEnclosure' => 0, // default = 0
                'useCustomColumnNullString' => 0, // default = 0
                'useCustomColumnEnclosureEscape' => 0, // default = 0             
            ],
        ),

        // General options for all datastores
        "autoDeleteTempFile" => true,
        "BOM" => true, // default bom = false
        "buffer" => 1000, // unit: KB ~ 1000 bytes. Default buffer = 1000 KB  
    ),
)
    ->toBrowser($text);

Sebastian Morales commented on Jun 3, 2022

Hi Ted, we will "footer" option for export to CSV function in the future version of Excel package. Meanwhile, you could use the Map process in your report setup to add a total row at the end of any datastore:

//MyReport.php
function setup()
{
    $totalRow = [];
    $this->src(...)
    ->pipe(...)
    ->pipe(new Map(array(
        "{value}" => function($row) use (&$totalRow) {
            if (!isset($totalRow["column_1"])) $totalRow["column_1"] = "Total";
            if (!isset($totalRow["column_2"])) $totalRow["column_2"] = 0;     
            $totalRow["column_2"] += $row["column_2"];      
            if (!isset($totalRow["column_3"])) $totalRow["column_3"] = 0;     
            $totalRow["column_3"] += $row["column_3"];   
            ...
            return $row;
        },
        "{end}" => function() use (&$totalRow) {
            return $totalRow;
        }
    )))
    ->pipe($this->dataStore("DatastoreAndTotalRow"));

Let us know if this works for you or not. 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
help needed

None