2017-06-06 16 views
0

對於聚合函數很容易做count,min,max,但我想要在分組行中獲取字符串concat值。角度ui網格標題中的自定義聚合函數獲取非數字值

什麼樣的自定義函數/聚合器我可以寫入聚合字符串值?

$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

目前,它是在國家進行分組,並給出彙總值最大和總和分別爲兩列年齡和平衡。我想將分組的性別行值顯示爲「男性,女性」。我怎樣才能做到這一點?

回答

0

我能解決它在我自己的,這裏是自定義函數添加CONCAT或有條件的字符串值回報 -

 { 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鏈接到的解決方案 - http://plnkr.co/edit/KVq7vC9cFb7uNc9edLYj?p=preview

相關問題