For your function to properly feed data, make sure to call this.selectAllNodes() within a setTimeout. Check out the modified stackblitz for reference.
setTimeout(()=>{
this.selectAllNodes()
})
NOTE: I noticed in your code that you are trying various methods to select items. I have simplified it using a recursive function.
The selected items that have changed are stored in this.treeComp.treeModel.selectedLeafNodeIds, so
getAllChecked()
{
const itemsChecked=this.getData(
this.treeComp.treeModel.selectedLeafNodeIds,null)
console.log(itemsChecked);
}
getData(nodesChanged,nodes) {
nodes=nodes||this.treeComp.treeModel.nodes
let data: any[] = []
nodes.forEach((node: any) => {
if (nodesChanged[node.id])
data.push({id:node.id,name:node.name})
if (node.children)
data=[...data,...this.getData(nodesChanged,node.children)]
}
);
return data
}
Update: I have enhanced the function getData to include the node's "parent", although I find @Raghul selvam's code more appealing than mine.
getData(nodesChanged,nodes,prefix) {
nodes=nodes||this.treeComp.treeModel.nodes
let data: any[] = []
nodes.forEach((node: any) => {
if (nodesChanged[node.id])
data.push(prefix?prefix+"."+node.name:node.name)
if (node.children)
data=[...data,...this.getData(nodesChanged,node.children,prefix?prefix+"."+node.name:node.name)]
}
);
return data
}
Simply call it like this
this.getData(this.treeComp.treeModel.selectedLeafNodeIds,null,"")