角度ui-grid标头中的自定义聚合函数获取非数字值

时间:2017-06-06 02:41:48

标签: angularjs angular-ui-grid aggregation ui-grid

对聚合函数执行count,min,max很容易,但我想在分组行中获取字符串concat值。

我可以编写哪种自定义函数/聚合器来聚合字符串值?

$scope.gridOptions = {
    enableFiltering: true,
    treeRowHeaderAlwaysVisible: false,
    columnDefs: [
      { name: 'name', width: '30%' },
      { name: 'gender', sort: { priority: 1, direction: 'asc' }, width: '20%', cellFilter: 'mapGender' },
      { name: 'age', treeAggregationType: uiGridGroupingConstants.aggregation.MAX, width: '20%' },
      { name: 'company', width: '25%' },
      { name: 'registered', width: '40%', cellFilter: 'date', type: 'date' },
      { name: 'state', grouping: { groupPriority: 0 }, sort: { priority: 0, direction: 'desc' }, width: '35%', cellTemplate: '<div><div ng-if="!col.grouping || col.grouping.groupPriority === undefined || col.grouping.groupPriority === null || ( row.groupHeader && col.grouping.groupPriority === row.treeLevel )" class="ui-grid-cell-contents" title="TOOLTIP">{{COL_FIELD CUSTOM_FILTERS}}</div></div>' },
      { name: 'balance', width: '25%', cellFilter: 'currency', treeAggregationType: uiGridGroupingConstants.aggregation.AVG, customTreeAggregationFinalizerFn: function( aggregation ) {
        aggregation.rendered = aggregation.value;
      } }
    ],
    onRegisterApi: function( gridApi ) {
      $scope.gridApi = gridApi;
    }

这是plunkr - http://plnkr.co/edit/KVq7vC9cFb7uNc9edLYj?p=preview

目前,它按国家分组,并分别给出两列Age和Balance的汇总值max和sum。我想将已分组的Gender行值显示为“Male,Female”。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

我能够自己解决它,这里是自定义函数添加concat或条件字符串值返回 -

{{1}}

解决方案的Plunkr链接 - Demo