Reputation: 117
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/javascript-grid-tree-data/
Upvotes: 0
Views: 1307
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