KoolReport's Forum

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

Putting the column header on a different line #2186

Open Richb201 opened this topic on on Jul 7, 2021 - 5 comments

Richb201 commented on Jul 7, 2021

Here is what I have:

and this is what I want

This is how I am making the columns: $this->src('substantiator')

        ->query($sql)
        ->pipe(new Transpose())
        ->pipe(new ColumnRename(array(
            "c0"=>"description",
              "c1"=>"amount"
            )))
        ->pipe($this->dataStore("6765_report"));

How can I move the column descriptors to a different row?

Sebastian Morales commented on Jul 8, 2021

Did you mean doing this in web view or excel export? Rgds,

Richb201 commented on Jul 8, 2021

Either.

Sebastian Morales commented on Jul 9, 2021

I think a general solution is to divide the data into two datastores and display both with Table widgets. The first Table doesn't show headers while the second one does. To divide a pipe to two datastores you could use the Map process like this:

        ->query($sql)
        ->pipe(new Transpose())
        ->pipe(new ColumnRename(array(
            "c0"=>"description",
              "c1"=>"amount"
            )))
        ->saveTo($tmpNode);

        $tmpNode->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row, $metaData, $index, $mapState) {
                if ($inddex < 5) return $row; // pipe the first 5 rows 
                else return null; // doesn't pipe the rest of rows
            }
        ))
        ->pipe($this->dataStore("First5RowsDatastore"));

        $tmpNode->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row, $metaData, $index, $mapState) {
                if ($inddex >= 5) return $row; // pipe rows after the first 5 ones
                else return null; // doesn't pipe the first 5 rows
            }
        ))
        ->pipe($this->dataStore("RestOfRowsDatastore"));

Or you could insert the header to the middle of your data:

        ->query($sql)
        ->pipe(new Transpose())
        ->pipe(new ColumnRename(array(
            "c0"=>"description",
              "c1"=>"amount"
            )))
        ->pipe(new \koolreport\processes\Map(array(
            "{value}" => function($row, $metaData, $index, $mapState) {
                $headerRow = [ "description" => "Description", "amount" => "Amount" ];
                if ($index === 5) return [$headerRow, $row];
                else return $row;                
            }
        ))
        ->pipe($this->dataStore("allDataStore"));

Then in your Table widget, use "cssClass"'s "tr" to decide if a row is the inserted header row and add a specific class for it to make its font bold:

Table::create(array(
    "dataSource" => $this->dataStore("allDataStore"),
    "showHeader" => false,
    "cssClass" => array(
        "tr" => function($row) {
            // if $row looks like a header row return some class like "inserted-header-row"
            // else return ""
        }            
    ...
?>
<style>
    tr.inserted-header-row td {
        font-style: bold;
    }
</style>
Richb201 commented on Jul 11, 2021

Using the first method by using 2 datastores, how do I tell exportToExcel to append the second, rather than overwrite the output file completely?

Sebastian Morales commented on Jul 12, 2021

Pls use excel template export with excel's Table widgets placement instead of export the datastores directly:

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

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