Slickgrid:具有动态参数的多个分组

时间:2015-08-24 04:45:37

标签: javascript jquery arrays parameter-passing slickgrid

我正在研究SlickGrid JS插件。我想基于表头动态地对Grid / Table进行分组。我应该如何动态传递参数[getter,formatter, aggregators]

没有像这样的硬编码

dataView.setGrouping([
    {
        getter : "department",
        collapsed : false,
        formatter : function(g){
            return g.value;
        },
        comparer : groupComparer
    },{
        getter : "faculty",
        collapsed : false,
        formatter : function(g){
            return g.value;
        },
        comparer : groupComparer
    }
]);

是否可以使用任何循环语句来生成Array个参数

1 个答案:

答案 0 :(得分:1)

我已经尝试了很多,并找到了这个解决方案

            arr=["department","faculty"];       //Dynamically generated array having titles to group
            var ar = []; //empty array to push parameters                                           
            for(i = 0; i < arr.length; i++)
            {                                       
                ar[i] = {
                        getter: arr[i],
                        formatter: function (g) {                               
                                return ":  " + g.value + "  <span style='color:green'>(" + g.count + " items)</span>";
                        },      
                        aggregators: [
                            new Slick.Data.Aggregators.Avg("percentComplete"),
                            new Slick.Data.Aggregators.Sum("cost")
                        ],
                        aggregateCollapsed: false,
                        lazyTotalsCalculation: false
                      };                      
            }               
            dataView.setGrouping(ar);