2

I'm using ui-grid and I'm grouping the data, I will need to get the group headers and the counters. How can I get those values?

This is an example of the grid

enter image description here

$scope.gridOptions = {
        enableFiltering: false,
        enableColumnResize: true,
        onRegisterApi: function (gridApi) {
            $scope.gridApi = gridApi;
        },        
        columnDefs: [
          { field: 'month',enableHiding: false, grouping: { groupPriority: 0 }, sort: { priority: 0, direction: 'desc' }},
          { field: 'facility',enableHiding: false,grouping: { groupPriority: 1 }, sort: { priority: 1, direction: 'asc' }}, 
         ...  
          { field: 'categorymanager',enableHiding: false, displayName:'CM', grouping:{ groupPriority: 2 }, sort: { priority: 2, direction: 'asc' }},
       ]
   };
Dayan
  • 7,634
  • 11
  • 49
  • 76

1 Answers1

0

You can get the values by writing a custom cellTemplate for the colDef. For example if you can define your template as:

let monthTemplate = '<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">{{grid.appScope.getValue(COL_FIELD, row.treeNode.children )}}</div></div>';

Then define your method as:

$scope.getValue = function(item, treeRowEntity){
      //item will hold month value
      //iterate over treerowentity array and get values
      //for example, if column required was facility
      treeRowEntity[0].row.entity.facility
    };
faizanjehangir
  • 2,771
  • 6
  • 45
  • 83