KoolReport's Forum

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

Summarise a column #2679

Open Ron opened this topic on on May 17, 2022 - 4 comments

Ron commented on May 17, 2022

I have a table with many columns. each column has many rows. I want to have in the end of last row the total of each column. I prefer not to use a DataGrid if possible

Ron commented on May 18, 2022

I can not specify the list of columns in the report code under columns table property. I have over 40 columns and the names are dynamically generated so I can not hard code it.

how can i generate a code for all the columns to have a sum in the footer?

Ron commented on May 19, 2022

?

Sebastian Morales commented on May 21, 2022

You could use Map process in report setup to create meta's "footer" for any column you want:

//MyReport.php 
->pipe(new Map(array(
    "{meta}" => function($meta) {
        $colMetas = $meta["columns"];
        foreach ($colMetas as $colName => $colMeta) {
            if ($footer_condition) $colMeta["footer"] = ...;
            $colMetas[$colName] = $colMeta;
        }
        $meta["columns"] = $colMetas;
        return $meta;
    }
)))

Another option is to create your "columns" setting dynamically in your Table/DataTables widget:

$columnNames = ...;
$columnSettings = [];
foreach ($columnNames as $columnName) { 
    $columnSettings[$columnName] = [
        ...
        "footer" => ...
    ];
}
Table::create([
    ...
    "columns" => $columnSettings,
]);

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