Any better approaches in achieving multi-column grouping in UI-Grid header?

一曲冷凌霜 提交于 2019-12-04 08:07:59

There is a much simpler solution. Write a customTreeAggregationFn that just calculates the identity of the row you wish to include in the grouping row:

var customTreeAggregationFn = function(aggregation, fieldValue, value, row) {
    // calculates the average of the squares of the values
    if (typeof(aggregation.count) === 'undefined') {
        aggregation.count = 0;
    }
    aggregation.count++;
    aggregation.value = value;
}

Then use this function and filter out non-header rows in the cellTemplate:

{
        name: 'EDM Id',
        displayName: 'EDM Id',
        field: 'Entity__r.EDM_ID__c',
        enableColumnMenu: false,
        customTreeAggregationFinalizerFn: function(aggregation) {
            aggregation.rendered = aggregation.value;
        },
        cellTemplate: '<div><div class="ui-grid-cell-contents" ng-if="row.groupHeader" title="TOOLTIP">{{COL_FIELD CUSTOM_FILTERS}}</div></div>',
        customTreeAggregationFn: customTreeAggregationFn

    }

Multi-column grouping isn't something the grid currently does, one of the barriers is the interaction with column moving and resizing.

Having said that, we'd like to have it, and looking at what you've done I reckon you could help to write that feature in ui-grid.

I'm not entirely sure how column grouping would work with column moving - perhaps it would always force the entire group to move, not just an individual column. With resizing basically the group column needs to have a width that equals the total of the sub columns.

That's basically what you've done already, the only trick is to fit it into the feature structure.

If you want to drop onto the gitter channel sometime https://gitter.im/angular-ui/ng-grid you'd probably find people would give you a hand with that PR (probably @c0bra would be best placed to help)

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