Ag- grid Selecting a parent should select the all children of it in tree data path

Viewed 1306

I am giving the data to grid with path (Tree Data). How Ican select the children if i select the parent node in ag-grid with tree legacy.

my data looks like below:

[{
name: 'File',
path:['file'],
isVisible: true
},
{
name: 'Save',
path:['file'],
isVisible: true
},
name: 'Export',
path:['file'],
isVisible: False
];
2 Answers

.html

    <ag-grid-angular 
    ....
    (rowSelected)="rowSelected($event)" 
    .... >
    </ag-grid-angular>

.ts

 rowSelected(event){
      event.node.childrenAfterGroup.forEach(a=>{
           a.selectThisNode(event.node.isSelected())
     })
 }

Pro Tip: Passing either undefined or null to selectThisNode makes it partially checked.

In order to select or deselect all children nodes of a parent node, just consider the following code. I solved my problem with this.

in .ts file:

rowSelected(event: any) {
   event.node.childrenAfterGroup.forEach(node => {
     node.selectThisNode(event.node.isSelected());
   });
}

and add the following rowSelected event notation into tag,

in html:

<ag-grid-angular 
....
(rowSelected)="rowSelected($event)" 
.... >
</ag-grid-angular>

P.S. I love coding :)

Related