PivotTable.js - sum aggregator does not show zeros

3.7k Views Asked by At

I am using PivotTable.js to pivot some data for a report. In the report, I have a need to show rows for which the aggregate sum is zero, and would like to display that zero in the totals column. When using the aggregatorTemplates.sum, the aggregate sum of zeros seems to be a black cell. I wonder if there is a way to render the zero?

A simplified example of what I'm doing is

var sum = $.pivotUtilities.aggregatorTemplates.sum;
var numberFormat = $.pivotUtilities.numberFormat;
var intFormat = numberFormat({digitsAfterDecimal: 0});

$("#output").pivot(
  [
    {color: "green", shape: "null", value: 0},
    {color: "blue", shape: "circle", value: 1},
    {color: "red", shape: "triangle", value: 2},
    {color: "blue", shape: "circle", value: 3},
    {color: "red", shape: "triangle", value: 4}
  ],
  {
    rows: ["color"],
    cols: ["shape"],
    aggregator: sum(intFormat)(["value"])
  }
);

This is the example from https://pivottable.js.org/examples/simple_agg.html, modified to illustrate the issue I'm facing. This is also available in a fiddle https://jsfiddle.net/rgs258/dky0hh1y/.

As a secondary question, I wonder if there's a way to hide the 'null' column in my example?

Any help or advice in resolving this is appreciated.

1

There are 1 best solutions below

4
On BEST ANSWER

(I'm the library author :)

You can override the built-in number formatting (which is hiding the zeros) by creating a locale file: https://github.com/nicolaskruchten/pivottable/wiki/Localization

You can hide the null columns using the filter or exclusions parameters: https://github.com/nicolaskruchten/pivottable/wiki/Parameters