PivotTable's and PivotMatrix's Field Order

Adding order number to row and column headers


PivotTable::create(array(
    ...
    'map' => array(
        'rowHeader' => function($rowHeader, $headerInfo) {
            $v = $rowHeader;
            if (isset($headerInfo['childOrder']))
                $v = $headerInfo['childOrder'] . ". " . $v;
            return $v;
        },
        'columnHeader' => function($colHeader, $headerInfo) {
            $v = $colHeader;
            if (isset($headerInfo['childOrder']))
                $v = $headerInfo['childOrder'] . ". " . $v;

            return $v;
        },
    ),
    ...
));
dollar_sales - sum | dollar_sales - count | dollar_sales - avg
1. Year-2004
2. Year-2005
Total
1. AV Stores, Co.
$99,984
35
$2,857
$0
0
$0
$99,984
35
$2,857
2. Amica Models & Co.
$82,223
26
$3,162
$0
0
$0
$82,223
26
$3,162
3. Anna's Decorations, Ltd
$0
0
$0
$56,932
19
$2,996
$56,932
19
$2,996
4. Alpha Cognac
$0
0
$0
$12,432
5
$2,486
$12,432
5
$2,486
5. Atelier graphique
$7,743
3
$2,581
$0
0
$0
$7,743
3
$2,581
Total
$189,951
64
$2,968
$69,365
24
$2,890
$259,315
88
$2,947



PivotMatrix::create(array(
    ...
    'map' => array(
        'rowHeader' => function($rowHeader, $headerInfo) {
            $v = $rowHeader;
            if (isset($headerInfo['childOrder']))
                $v = $headerInfo['childOrder'] . ". " . $v;
            return $v;
        },
        'columnHeader' => function($colHeader, $headerInfo) {
            $v = $colHeader;
            if (isset($headerInfo['childOrder']))
                $v = $headerInfo['childOrder'] . ". " . $v;

            return $v;
        },
    ),
    ...
));
 
  dollar_sales - sum   dollar_sales - count   dollar_sales - avg  
  orderYear   orderQuarter  
  customerName   productLine   productName  
1. Year-2004
2. Year-2005
Total
1. AV Stores, Co.
2. Amica Models & Co.
3. Anna's Decorations, Ltd
4. Alpha Cognac
5. Atelier graphique
Total
$99,984
35
$2,857
$0
0
$0
$99,984
35
$2,857
$82,223
26
$3,162
$0
0
$0
$82,223
26
$3,162
$0
0
$0
$56,932
19
$2,996
$56,932
19
$2,996
$0
0
$0
$12,432
5
$2,486
$12,432
5
$2,486
$7,743
3
$2,581
$0
0
$0
$7,743
3
$2,581
$189,951
64
$2,968
$69,365
24
$2,890
$259,315
88
$2,947
Page size:
Description

This example show how to customize the row header and column header of Pivot Table and PivotMatrix widget.

Under the "map" property, you add "rowHeader" and "columnHeader" sub properties. Those properties are defined by a function that will receive row or column header text as parameters. You can add custom processes to transform the row and column headers to desired one and return it.

As you can see in above example, the row and column header of pivot are prefixed with order: "AV Stores, Co." becomes "1. AV Stores, Co.".