且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ExtJS 6.2根据摘要行对网格面板分组进行排序

更新时间:2021-07-05 19:33:08

可以使用带有 sorterFn 分组器完成此操作。 sorterFn 应该比较您要排序的摘要值。对于您提到的厨房水槽示例,如果要按照项目列进行分组,按照估计列的总和进行排序,则石斑鱼将如下所示:

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;
        }
}]

可以使用:

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

看到小提琴: https://fiddle.sencha.com/#fiddle/1im3