KoolReport's Forum

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

Data Handling after Transpose() Process #907

Closed hsw opened this topic on on Jun 6, 2019 - 3 comments

hsw commented on Jun 6, 2019

Hi Koolreport,

The report I am planning to build has to make use of the Transpose process.to switch rows to columns. I could not find any example for me to reference. I need to understand how flexible it is for me to customise and format the data by rows after transpose().

Qn1. After the Transpose, the column names are c0, c1, c2 etc. The actual header names from my csv data file is under column c0. How do I label/ re-name individual header names under Column c0?

Qn2. How do I format the data for certain rows? Let say, one of the rows output integers, how do I format the integers to $9,999?

Thank you

David Winterburn commented on Jun 6, 2019

Hi there,

Beside the Transpose process there's also Transpose2 which uses the values of the first column as the column names of the transposed table.

To format columns you could use the ColumnMeta process. To format certain column or row please try the Map process:

->pipe(new \koolreport\processes\Map([
    "{value}" => function($row, $meta) {
        //modify the row
        if (isThisTheRow($row)) {
            $row["column1"] = "$" . number_format($row["column1"], 0);
        }
        ...
        //return the row to next process or datastore
        return $row;
    }
]))

Let us know if you have any difficulty in specific cases. Thanks!

KoolReport commented on Jun 6, 2019

Hi hsw,

Yes, after the Tranpose(), the column will be named c0 to cn. In order to change name, you may use the ColumnRename

->pipe(new ColumnRename(array(
    "c0"=>"id"
    "c1"=>"name"
    "c3"=>"amount"
)))

After transpose, some of your column will contains different data types. If you want to format that value base on rows, you need to use custom formatValue in Table, for example:

Table::create(array(
    "columns"=>array(
        "c0"=>array(
            "formatValue"=>function($value)
            {
                if(gettype($value)=="int")
                {
                    return "$".number_format($value);
                }
                return $value;
            }
        )
    )
))

Hope that helps.

hsw commented on Jun 8, 2019

Hi,

Thanks for the answers. Let me try out.

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