KoolReport's Forum

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

Dynamic Table Column #2768

Open hsw opened this topic on on Jul 27 - 5 comments

hsw commented on Jul 27


I am making a report that shows the top 6 products, presented in 6 columns.

After Filter process, Limit process, only 6 rows of data are selected, and then uses the Transpose() process to switch the 6 rows to 6 columns.

At the view.php file, I assign the Label for each column c0 to " ", c1 to P1, c2 to P2, c3 to P3, c4 to P4, c5 to P5, c6 to P6.

The report output nicely in 6 columns.

But there could be scenario when the Datastore ends up with less than 6 columns. Let say there are only 4 columns, the report outputs " ",P1, P2, P3, c4, c5, c6. (c4 to c6 are the default empty data rows).

Is there a way to make the Table column dynamic?

Thank you.

Sebastian Morales commented on Jul 28

If you unset "columns" property of a Table it will be created dynamically. You can also get list of columns from a datastore by using $ds->meta()["columns"].

hsw commented on Jul 31

Thank you. Let me try it out.

hsw commented on Aug 2


I manage to output the columns dynamically, by removing the column attribute. But the header is showing c0, c1, c2, c3... How to suppress this header and replace with my own headers?

Thank you.

Sebastian Morales commented on Aug 2

In your report view:

// MyReport.view.php
$columns = $this->dataStore(...)->meta()["columns"];
foreach ($columns as $colKey => $colMeta) {
    $columns[$colKey]["label"] = str_replace("c", "P", $colKey); // replace c1 with P1, c2 with P2, etc
    "columns" => $columns,

Let us know how it works. Tks,

hsw commented 7 days ago

Hi Sebastian,

Thanks for the suggestion. It works perfectly. I also managed to set the cssStyle for the columns.

This software is really flexible in building reporting solutions.

Thank you.

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