ng2-tree icon indicating copy to clipboard operation
ng2-tree copied to clipboard

Cannot Expand all in dynamic tree

Open N3uR02812 opened this issue 6 years ago • 0 comments

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

N3uR02812 avatar Jun 08 '18 08:06 N3uR02812