ExtJS 6.2 Sort grid Panel groupings based on summa

2019-07-23 18:30发布

I've been searching for hours to figure out how to do this. Essentially what I want to do is group data based on one column, create a summary for that grouping, then sort the groups based on the summary.

Using one of their kitchen sink examples, I would like to be able to sort these groups by summary value rate.

http://examples.sencha.com/extjs/6.0.0/examples/classic/grid/group-summary-grid.html

1条回答
老娘就宠你
2楼-- · 2019-07-23 19:11

This can be done using a grouper with a sorterFn. The sorterFn should compare the summary values you are sorting by. For the kitchen sink example you mentioned, if you want to sort by the sum of the estimate column while grouping by the project column, the grouper would look like:

groupers: [{
    property: 'project',
    sorterFn: function(a,b) {

        var suma=0; store.each(function (rec) { suma += rec.data.project === a.data.project ? rec.data.estimate:0; });
        var sumb=0; store.each(function (rec) { sumb += rec.data.project === b.data.project ? rec.data.estimate:0; });

        if (suma > sumb) return 1;
        if (suma < sumb) return -1;
        return 0;
        }
}]

The grouper can be applied using:

store.group(store.groupers[0]);

See fiddle: https://fiddle.sencha.com/#fiddle/1im3

查看更多
登录 后发表回答