aggFunc shows value of only immediate children (ag-grid), I need leaf level children count

23 Views Asked by At

I have a structure like the following using ag-grid react: enter image description here

The first column of "Them" has row-grouping enabled, which gives accurate values of leaf children count in parentheses. I have another column called "Status" which uses an aggFunc: (params) => params.value.length. There is no grouping on this column. It generates what is shown in the image below. But I want that 4 to be 20, as in replicating the behavior of the row-grouping count. How can I achieve this?

1

There are 1 best solutions below

0
nd10 On

This is a little tricky because the 'aggFunc' only get the values and not the node references. Here's a workaround to make it work: Instead of checking the length, try setting the value to a variable at root level and then rolling it up.

  1. For each GrandChild add a custom value, set it to 1. {..., COUNT: 1}
  2. Add a hidden column to the grid: {..., field: 'COUNT', aggFunc: 'sum', hidden: true}
  3. Now in your custom renderer for 'STATUS' column, show actual value of leaf nodes and 'COUNT' for grouped nodes.

Let me know if you still need some clarification.