Search code examples
angularag-gridag-grid-angular

Aggrid create column which displays value for certain group


I have an aggrid table which uses row grouping

 {
  field: 'day',
  hide: true,
  rowGroup: true,
  cellRenderer:'agGroupCellRenderer',
},
{
  field: 'shift',
  hide: true,
  rowGroup: true,
  cellRenderer:'agGroupCellRenderer',
}

...

groupDisplayType: 'groupRows',
groupRowRenderer: 'agGroupCellRenderer',

enter image description here

What I am trying to do is to add a column Value if Grouped which displays values only on the grouped row shift (Break, Early Shift, Late Shift). Not in the day row, nor in a leaf.

I tried several things but without success.

I thought I just create a simple column with cellRenderer

{
  colId: 'Value if Grouped',
  cellRenderer: (params) => {
    if (params.node.group === 'shift') { // is just pseudecode
      return '123';
    }
  }
}

But the cell renderer is only called when I open the group and am on leaf-level.

Any ideas how I can write code to just display a value on the group level day?


Solution

  • This can be done using the aggregate function and cell renderer. Plunker Demo Link

    {
      field: 'total',
      aggFunc: 'sum',
      cellRenderer: (params) => {
          return params.node.level === 0 ? params.node.aggData.total : '' 
      }
    },      
    

    enter image description here