KoolReport's Forum

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

Is it possible to rename the {{all}} row label for PivotExtract #1816

Closed Venom opened this topic on on Jan 4, 2021 - 2 comments

Venom commented on Jan 4, 2021

In the example of pivotExtract, https://www.koolreport.com/examples/reports/pivot/pivot_extract/

Is it possible to rename the {{all}} label for Row and Column?

Screen shot

David Winterburn commented on Jan 5, 2021

After PivotExtract, use the Map process to change the columns and rows like this:

    ->pipe(new PivotExtract(...))
    ->pipe(new Map(array(
        "{value}" => function($row) {
            foreach ($row as $colName => $value} {
                $newColName = str_replace("{{all}}", "Total", $colname);
                $row[$newColName] = $value;
                unset($row[$colname]);
            }
            $row["customerName"] = str_replace("{{all}}", "Total", $row["customerName"]);
            return $row;    
        }
    )))        
Venom commented on Jan 5, 2021

Thank you for your support. I have modified a bit as below.

    ->pipe(new PivotExtract(...))
    ->pipe(new Map(array(
        "{value}" => function($row) {
            foreach ($row as $colname => $value} {
                $newColName = str_replace("{{all}}", "Total", $colname);
                $row[$newColName] = $value;
                if($colname != $newColName){  //if new column name is different from old one, then unset
                    unset($row[$colname]);
                }
            }
            $row["customerName"] = str_replace("{{all}}", "Total", $row["customerName"]);
            return $row;    
        }
    )))   

Screenshot

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
solved

None