PivotTable's and PivotMatrix's Map

Mapping fields, headers and data cells


PivotTable::create(array(
    ...
    'map' => array(
        'dataField' => function($dataField, $fieldInfo) {
            $v = $dataField;
            if ($v === 'dollar_sales - sum')
                $v = 'Sales (in USD)';
            else if ($v === 'dollar_sales - count')
                $v = 'Number of Sales';
            else if ($v === 'dollar_sales - avg')
                $v = 'Sales Average';
            return $v;
        },
        'rowHeader' => function($rowHeader, $headerInfo) {
            return $rowHeader;
        },
        'columnHeader' => function($colHeader, $headerInfo) {
            return $colHeader;
        },
        'dataCell' => function($value, $cellInfo) {
            return $value;
        },
    ),
    ...
));



PivotMatrix::create(array(
    ...
    'map' => array(
        'rowField' => function($rowField, $fieldInfo) {
            $v = $dataField;
            if ($v === 'customerName')
                $v = 'Customer';
            else if ($v === 'productLine')
                $v = 'Category';
            else if ($v === 'productName')
                $v = 'Product';
            return $v;
        },
        'columnField' => function($colField, $fieldInfo) {
            $v = $dataField;
            if ($v === 'orderYear')
                $v = 'Year';
            else if ($v === 'orderMonth')
                $v = 'Month';
            return $v;
        },
        'rowHeader' => function($rowHeader, $headerInfo) {
            return $rowHeader;
        },
        'columnHeader' => function($colHeader, $headerInfo) {
            return $colHeader;
        },
        'dataCell' => function($value, $cellInfo) {
            return $value;
        },
    ),
    ...
));
 
  dollar_sales - sum  
  Year   orderQuarter  
  Customer   Category   Product  
2004
2005
Total
Total
Total
AV Stores, Co.
Total
Amica Models & Co.
Total
Anna's Decorations, Ltd
Total
Alpha Cognac
Total
Atelier graphique
Total
Total
99984.4
-
99984.4
82223.23
-
82223.23
-
56932.3
56932.3
-
12432.32
12432.32
7742.92
-
7742.92
189950.55
69364.62
259315.17
Page size:
Description