ng2-tree
ng2-tree copied to clipboard
Cannot Expand all in dynamic tree
Hello,
I try to implement an Expand/Collapse-All function in a dynamic tree.
The functions are looking like this:
`public expandAll(): void { //Initial Root const nodeController = this.treeComponent.getController();
//Do to Leafs
var currentModel = nodeController.toTreeModel();
this.doRecursive(currentModel, (contr:TreeController) =>{
if(contr != null && contr.isCollapsed())
{
contr.reloadChildren();
contr.expand();
}
});
}
public collapseAll(): void {
//Initial Root
const nodeController = this.treeComponent.getController();
//Do to Leafs
var currentModel = nodeController.toTreeModel();
this.doRecursive(currentModel, (contr:TreeController) => {
if(contr != null && contr.isExpanded())
{
contr.collapse();
}
});
}
public doRecursive(currentModel: TreeModel, operation: (controller: TreeController)=> void):void
{
var controller = this.treeComponent.getControllerByNodeId(currentModel.id);
operation(controller);
currentModel.children.forEach(s=>{
this.doRecursive(s,operation);
});
}`
The Collapse works but when i try to collapse all, it doesn't work. In your Demo there are all Controllers in the TreeService, but in my dynamic Tree (with loadChildren), there are only the one who are currently shown. So my expand function doesnt work only for the node, they are already shown.
Is there any method to do this or is there any workaround?
Greetings