最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use grouping and aggregates on Slick Grid - Stack Overflow

programmeradmin2浏览0评论

I'm trying to understand how grouping and aggregates work with the slick grid. I have some data that I want to group in a tree like structure somewhat how it's done on this examples page:

However, I can't find any documentation on setGrouping or on what exactly aggregates are. This page doesn't have any documentation, just code, no useful ments on what the code is for or how it's used.

Does anyone know a good resource for this? Google isn't giving me much info either.

For instance, in this code:

dataView.setGrouping({
getter: "duration",
formatter: function (g) {
  return "Duration:  " + 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
});

I get what the getter and formatter are used for, but what are the aggregators used for? Is this what actually groups them together in the tree view? I don't see where percentComplete and cost e into play because it's grouping by duration.

I'm trying to understand how grouping and aggregates work with the slick grid. I have some data that I want to group in a tree like structure somewhat how it's done on this examples page:

http://mleibman.github.io/SlickGrid/examples/example-grouping

However, I can't find any documentation on setGrouping or on what exactly aggregates are. This page doesn't have any documentation, just code, no useful ments on what the code is for or how it's used.

Does anyone know a good resource for this? Google isn't giving me much info either.

For instance, in this code:

dataView.setGrouping({
getter: "duration",
formatter: function (g) {
  return "Duration:  " + 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
});

I get what the getter and formatter are used for, but what are the aggregators used for? Is this what actually groups them together in the tree view? I don't see where percentComplete and cost e into play because it's grouping by duration.

Share Improve this question asked Apr 16, 2013 at 14:46 Rocky PulleyRocky Pulley 23.3k21 gold badges70 silver badges109 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Let me try answering you in a way you'll understand, first of all a definition... An aggregate is a collection of items that are gathered together to form a total quantity. The total in question could be a sum of all the fields, an average or other type of aggregator you might define. So basically it's the action of regrouping by the column you chose and give the calculation result of the group. Alright now how does it work in the case of a SlickGrid? You need to define what kind of Aggregator you want to use (Avg, Sum, etc...), defining them will do the calculation BUT unless you attach it to the field, nothing will be displayed, so in the example you found it is very important to attach/bind this groupTotalsFormatter: sumTotalsFormatter to your columns definition, as for example:

..., {id: "cost", name: "Cost", field: "cost", width: 90, sortable: true, groupTotalsFormatter: sumTotalsFormatter}, ...

so let's recap... Once the Aggregator is define new Slick.Data.Aggregators.Sum("cost") it will do the calculation but unless it's bind to the field nothing will be displayed. As an extra option, the aggregateCollapsed (true/false) is to display the sub-total (avg, sum or whatever) inside or outside the group when you collapse.

发布评论

评论列表(0)

  1. 暂无评论