In this example we define a formula
['new_col', function (rd) {
var a = rd['1998_aggr_Freight'], b = rd['1997_aggr_Freight'];
return (isNaN(a) ? 0 : a) - (isNaN(b) ? 0 : b);
}]
for a new column in final pivot view. Column is added by simple array manipulation of ui.CM
argument of pivotCM event.
pivotCM: function (evt, ui) {
//add new column.
ui.CM.push({
title: '1998-1997',
width: 120,
dataIndx: 'new_col',
dataType: 'float',
render: function (ui) {
//conditional background color depending upon value of cell.
return { style: 'background-color:' + (ui.cellData > 0 ? '#aaffaa' : '#ffaaaa;') };
},
summary: { type: 'sum' },
format: '$##,###.00',
styleHead: {
color: '#ff0000',
'font-weight': 'bold'
}
})
}