precious
precious

Reputation: 117

Count total rows excluding children rows

I have a requirement for display only row count of parent rows in tree data mode. I am using getDisplayedRowCount api it gives me all the row count i.e parent + child (if expanded). Is there any way to do it?

For example If we have rows like below where 2 row has child and 1 row has no child then just count as 3 . dont count children. Just count parent row and row without children

Result count : 3 of 3

Parent row 1 --- Child row

Parent row 2 --- child row

Row without child

For example, if we have tree structure like in the example . How to only count A, C and E? and show count as 3 on top of grid

https://www.ag-grid.com/example-runner/grid-react.php?section=javascript-grid-tree-data&example=filler-nodes&generated=1&clientside=1&rowgrouping=1&enterprise=1&grid=%7B%22noStyle%22%3A0%2C%22height%22%3A%22100%25%22%2C%22width%22%3A%22100%25%22%2C%22enterprise%22%3Atrue%7D

https://www.ag-grid.com/javascript-grid-tree-data/

Upvotes: 0

Views: 1307

Answers (1)

Shuheb
Shuheb

Reputation: 2352

One possible solution would be to rely on the fact that the parent node of the nodes A, C & E (in your given example) is the root node - note that this is not documented in the official documentation, however it is the simplest solution I can think of.

If a node has the root node as the parent, then we can call it a parent node. You can verify this by adding this code and look at the nodes which are printed:

gridOptions.api.forEachNode((node) => {
    if (node.parent.id == 'ROOT_NODE_ID') {
      console.log(node.key);
    }
  });

I've put together an example showing this at the click of a button

Upvotes: 1

Related Questions