KoolReport's Forum

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

Export - Sparkline not in Datatable after Update (to koolreport 5) #1728

Closed Thomas opened this topic on on Nov 23, 2020 - 4 comments

Thomas commented on Nov 23, 2020

Hi,

I've just updated koolreport (composer) and checked my recent reports. In my export the Sparklines are not in the Datatable row but outside (before) the datatable.

NOW:

BEFORE:

Here is the related code:

"columns"=>array(
            "Aspekt" => array(
                    "label" => "Bereich",
                    "type"=>"string",
                    
            ),
            "title" => array(
                    "label" => "Nr.",
                    "type"=>"string",
            ),
            "Bereich" => array(
                    "label" => "Dimension",
                    "type"=>"string",
            ),
            "question" => array(
                    "label" => "Frage",
                    "type"=>"string",
            ),
            "a Verteilung" => array(
                "label" => "IST <br> &#128202;",
                'formatValue' => function($val, $row) use ($groups_data_verteilung, $report_group_main , $color) {
                    return sparklines\Bar::create(array(
                        "data" => $groups_data_verteilung[$report_group_main]['a'][$row["title"]],
                        "height"=>"35px",
                        "options"=>array(
                            "barWidth"=>"10px",
                            "barColor"=> $color['ist'],
                        ),
                    ));
                }
            ),
David Winterburn commented on Nov 24, 2020

Hi Thomas,

Thanks for your feedback! We've checked and confirmed this is a bug with the new version of DataTables. We will release a fixed version soon. In the meantime you could apply this fix yourself:

Open the file koolreport/datagrid/DataTables.php and replace the following line:

    $dataRow[$key] = $this->formatValue($value, $cMeta, $row, $cKey);

with these ones:

    ob_start();
    echo $this->formatValue($value, $cMeta, $row, $cKey);
    $dataRow[$key] = ob_get_clean();

Let us know how it works for you. Thanks!

Thomas commented on Nov 24, 2020

Hi David, that doesn't work. With this change, there are no charts or DataTables and the content is rendered as html and not pdf.

David Winterburn commented on Nov 24, 2020

Well, I made some mistake in the previous guide. Please wrap the three new lines in curly braces:

{
    ob_start();
    echo $this->formatValue($value, $cMeta, $row, $cKey);
    $dataRow[$key] = ob_get_clean();
}

or replace the original lines:

if (is_callable($formatValue))
    $dataRow[$key] = $this->formatValue($value, $cMeta, $row, $cKey);

with these updated ones:

if (is_object($formatValue) && is_callable($formatValue)) {
    ob_start();
    echo $this->formatValue($value, $cMeta, $row, $cKey);
    $dataRow[$key] = ob_get_clean();
}

Thanks!

Thomas commented on Nov 24, 2020

That worked. Thank you David.

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
bug
solved

DataGrid