gpt4 book ai didi

javascript - 有没有办法在pivottable.js中设置pivot列的顺序?

转载 作者:行者123 更新时间:2023-12-02 23:36:02 27 4
gpt4 key购买 nike

我想在我的网站中创建数据透视表。因此,我使用 pivottable.js 来创建数据透视表。

我可以使用以下 JS 创建数据透视表,但无法设置列的顺序。

以下代码用于生成数据透视表。

$(document).ready(function(){
var sum = $.pivotUtilities.aggregatorTemplates.sum;
var numberFormat = $.pivotUtilities.numberFormat;
var intFormat = numberFormat({digitsAfterDecimal: 0});
$("#raw_data_op").pivot(
[
["id","mycount","type","date"],
["Name1","10","Emp1","1/1/2010"],
["Name1","13","Emp2","1/1/2010"],
["Name1","14","Emp1","1/2/2010"],
["Name1","10","Emp2","1/2/2010"],
["Name1","14","Emp1","1/3/2010"],
["Name1","12","Emp2","1/3/2010"],
["Name2","11","Emp1","1/1/2010"],
["Name2","13","Emp2","1/1/2010"],
["Name2","18","Emp1","1/2/2010"],
["Name2","10","Emp2","1/2/2010"],
["Name2","9","Emp1","1/3/2010"],
["Name2","17","Emp2","1/3/2010"],
["Name3","9","Emp1","1/1/2010"],
["Name3","0","Emp2","1/1/2010"],
["Name3","10","Emp1","1/2/2010"],
["Name3","12","Emp2","1/2/2010"],
["Name3","19","Emp1","1/3/2010"],
["Name3","10","Emp2","1/3/2010"],
], {
rows: ["id"],
cols: ["date","type"],
aggregator: sum(intFormat)(["mycount"])
});
});

当前结果:-

Current Result

我们可以在列序列中首先得到Emp2,而不是Emp1吗?

最佳答案

是的,您可以使用sorters配置选项。类似的东西

sorters: {"type": $.pivotUtilities.sortAs(["Emp2", "Emp1"])}

或者一般来说,您可以传入任何旧的比较器:

sorters: {"type": function(a,b){ return string_a.localeCompare(string_b) }

关于javascript - 有没有办法在pivottable.js中设置pivot列的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56292094/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com