I am using the enterprise version of ag grid. I have a custom context menu and inside there are many parent nodes and inside each parent node, there are nested child nodes.Currently I can expand it by the parent level, but don't know how to expand all child nodes at the same time. Any help will be highly appreciated. Thanks
{
name: 'Expand All',
action() {
params.api.forEachNode((node, index) => {
if (node.group && node.groupData['ag-Grid-AutoColumn'] ===
params.value) {
node.setExpanded(true);
}
});
}
I faced the same issue with AG Grid, Unfortunately I couldn't find anything useful in AG Grid API to achieve this functionality. So I had to achieve it in this way:
name: 'Expand All',
action: () => {
let totalChildNodes = 0;
let checkCount = 0;
params.api.forEachNode((node, index) => {
if (node.group && node.groupData['ag-Grid-AutoColumn'] === params.value) {
totalChildNodes = node.allChildrenCount;
node.expanded = true;
}
if (totalChildNodes > 0 && checkCount <= totalChildNodes) {
checkCount++;
node.expanded = true;
}
});
params.api.onGroupExpandedOrCollapsed();
}
What the above code does is it checks the clicked node and get it's child count and then expand all its child nodes as well.