KoolReport's Forum

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

Table and add empty row #2738

Open Edp Ferrino opened this topic on on Jun 23 - 5 comments

Edp Ferrino commented on Jun 23

Hi, I have created a table from a series of records. So far it has been easy. Now I would like to insert blank lines when the SECTION is changed


Before ID;SECTION;NAME;VALUE 1;AB;First Record;5.0 2;AB;Second Record;8.2 3;AC;N Record;4.8

After ID;SECTION;NAME;VALUE empty row AB empty row 1;First Record;5.0 2;Second Record;8.2 empty row AC empty row 3;N Record;4.8

Sebastian Morales commented on Jun 23

You can try the Map process to insert empty row or any rows according to your condition like this:

$lastRow = [];
->pipe(new Map(array(
    '{value}' => function($row, $metaData, $index, $mapState) use (&$lastRow) {
        if ($index > 0) { // only insert empty row after the first row
            $lastId = $lastRow['id'] ?? null;
            $currentId = $row['id'] ?? null;
            if ($currentId !== $lastId) { // new section
                $emptyRow = ...;
                $lastRow = $row;
                return [$emptyRow, $row];
            } else {
                $lastRow = $row;
                return $row;
        } else if ($index == 0) { // the first row
            $lastRow = $row;
            return $row;

This is only a suggestion. You can change the condition if ($currentId !== $lastId) to what you want. Let us know if this works for your case. Rgds,

Edp Ferrino commented on Jun 24

I don't understand where I deco to use it. In the setup?

Sebastian Morales commented on Jun 24

Yes, this Map process should be in your report's setup method, just before piping to your datastore.

Edp Ferrino commented on Jun 24

If replace ... with

'<tr><td>' . $currentId . '</td><td></td><td></td><td>0</td></tr>';

Return this error:

Warning: number_format() expects parameter 1 to be float, string given in /var/www/ferrino/plugins/koolreport_pro_5.16.2/koolreport/core/src/core/Utility.php on line 148

Sebastian Morales commented on Jun 24

Your row should only contain the data, i.e string or number or date string or boolean value. Html tags like <tr>, <td> are rendered by Table widget, you don't need to include them in your row data. Thus:

    $emptyRow = ['id' => $currentId];


    $emptyRow = [];

is a possible solution.

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