Hi Sebastian,
sure no problem and thanks for your support:
Lets image I had this data:
Row | Category | Score | Max
A X 2 2
A Y 3 5
A X 1 4
B X 2 2
B Y 2 3
B Y 4 5
B X 3 3
C Y 2 4
C Y 1 1
D X 2 5
D Y 1 1
D Y 0 1
E X 2 3
F Y 2 2
F X 2 4
I have a select to filter for the category. That means if I don't apply a filter the pivot table looks like this:
Row | Score | Max
A 6 11
B 11 13
C 3 5
D 3 7
E 2 3
F 4 6
However, instead of the two column Score and Max, I'd like to show a percentage = Score *100 / Max %
It should look like this:
Row | Percentage
A 54.54%
B 84.62%
C 60.00%
D 42.86%
E 66.67%
F 66.67%
I currently achieve that using the mapping functionality for the datacell:
'map' => [
'dataCell' => function($v, $ci) {
if ($ci['fieldName'] === 'score - sum') {
return sprintf("%.2f%%", $ci['indexToData'][$ci['rowIndex']][$ci['columnIndex']]['max - sum'] > 0 ? $ci['indexToData'][$ci['rowIndex']][$ci['columnIndex']]['score - sum] / $ci['indexToData'][$ci['rowIndex']][$ci['columnIndex']]['max- sum'] * 100: 0 );
} else {
return $v;
}
My problem is that I now want to sort the field by the percentage. That means my end result should look like this:
Row | Percentage
B 84.62%
E 66.67%
F 66.67%
C 60.00%
A 54.54%
D 42.86%
However, if I apply the sort functionality like this:
'rowSort' => array(
'score- sum' => 'desc'
),
It uses the values before the mapping so that I don't get the result above.
I also have the category above for which I need to be able to filter. In my real life example I have a couple of categories and various filter.
I hope this helps. Thanks a lot!
Christian