我正在使用PivotTable.js为报表透视一些数据。在报告中,我需要显示合计和为零的行,并希望在totals列中显示该零。在使用aggregatorTemplates.sum时,0的总和似乎是一个黑色单元格。我想知道是否有一种方法可以渲染零?
我正在做的一个简化示例是
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"])
}
);这是来自https://pivottable.js.org/examples/simple_agg.html的示例,经过修改以说明我面临的问题。这在fiddle https://jsfiddle.net/rgs258/dky0hh1y/中也是可用的。
作为第二个问题,我想知道是否有一种方法可以隐藏我示例中的“null”列?
在解决这个问题上的任何帮助或建议都是非常感谢的。
发布于 2017-07-26 23:17:56
(我是库的作者:)
您可以通过创建语言环境文件来覆盖内置的数字格式(隐藏零):https://github.com/nicolaskruchten/pivottable/wiki/Localization
您可以使用filter或exclusions参数隐藏空列:https://github.com/nicolaskruchten/pivottable/wiki/Parameters
https://stackoverflow.com/questions/45246543
复制相似问题