KoolReport's Forum

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

Apply color to Pivot-data-cell value #738

Open Daniel Amamoo-Otchere opened this topic on on Mar 11, 2019 - 1 comments

Daniel Amamoo-Otchere commented on Mar 11, 2019

Hello, I have another request

I tried to achieve the snapshot above with this code but it did not work.

  PivotTable::create(array(
            "dataStore"=>$this->dataStore("pivot_data"),
                      
            "rowDimension"=>"row",
            "columnDimension"=>"column",
            "measures"=>array(
                "lab_result - max"=>array(
                    'formatValue'=>"<p style='color:red'>@value</p>",
                    )
  ),

How do I apply the red color to the measure value?

David Winterburn commented on Mar 12, 2019

Hi Daniel,

To customize pivot table's or pivot matrix's headers or data cells, please their "map" property:

PivotTable::create([
	...
	'map' => array(
		'rowHeader' => function($rowHeader, $headerInfo) {
			// Util::prettyPrint($headerInfo);
			$v = $rowHeader;
			if (isset($headerInfo['childOrder']))
				$v = $headerInfo['childOrder'] . ". " . $v;
			return $v;
		},
		'columnHeader' => function($colHeader, $headerInfo) {
			$v = $colHeader;
			if ($headerInfo['fieldName'] === 'orderYear')
				$v = 'Year-' . $v;
			else if ($headerInfo['fieldName'] === 'orderQuarter')
				$v = 'Quarter-' . $v;

			if (isset($headerInfo['childOrder']))
				$v = $headerInfo['childOrder'] . ". " . $v;
			return $v;
		},
		'dataCell' => function($value, $cellInfo) {
			// Util::prettyPrint($cellInfo);
			$rfOrder = $cellInfo['row']['fieldOrder'];
			$cfOrder = $cellInfo['column']['fieldOrder'];
			$df = $cellInfo['fieldName'];
			$dfOrder = $cellInfo['fieldOrder'];
			// return "$rfOrder:$cfOrder:$df. $value";
			
			return $cellInfo['formattedValue'];
		},
	),
	...
]);

You could modify the values or put them in a classed element for setting colors with CSS, etc. Let us know if you need further help. Thanks!

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