ExtJS 6.2 Sort grid Panel groupings based on summary row

一曲冷凌霜 提交于 2019-12-11 05:25:17

问题


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:


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



来源:https://stackoverflow.com/questions/40074010/extjs-6-2-sort-grid-panel-groupings-based-on-summary-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!