I’ve added my source data, updated the configuration of the widget, run the sample locally, and I get the expected result.
It is basically a sales report where rows contain product brands and categories, and columns sum up sales (amount and quantity) by year (current and previous year). Nothing really new so far.
Next request was to display, for each row, the difference (as a perecentage) for amounts and quantity between the current year and the previous one.
One last suggestion: if I set a filter, the added columns are lost; I suppose I should re-run the code to define the new columns again. If so, which event should I attach an handler to?
Yes, applying filters will redraw pivot. We are going to add onHeaderInit event that will allows to customize columns.
The existent version will require more complicated solution:
enable “totalColumn” for your pivot to add columns. These new columns apply sum calculation, but it is possible to change their math template;
set onBeforeRender event handler to DataTable of Pivot. There you will need to iterate over “columns” array to exclude (sum) from header text and math calculation for last 2 columns.