0

It's easy to do count, min, max for the aggregate functions, but I would like to get string concat value in the grouped row.

What kind of custom function/aggregator I can write to aggregate string values?

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

Here is plunkr - http://plnkr.co/edit/KVq7vC9cFb7uNc9edLYj?p=preview

Currently, it's grouped on State and gives aggregated value max and sum for two columns Age and Balance respectively. I want to display grouped Gender row value as "Male, Female". How can I do that?

1 Answer 1

2

I was able to resolve it on my own, here is the custom function to add concat or conditional string value return -

     { name: 'company', width: '25%',
        customTreeAggregationFn : function( aggregation, fieldValue, numValue, row ) {
          if(!aggregation.value){
           aggregation.value = row.entity.company;
          }
        },
        customTreeAggregationFinalizerFn: function( aggregation ) {
         aggregation.rendered = aggregation.value;
        }
      }

Plunkr link to the solution - http://plnkr.co/edit/KVq7vC9cFb7uNc9edLYj?p=preview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.