CirclonGroup / angular-tree-component

A simple yet powerful tree component for Angular (>=2)
https://angular2-tree.readme.io/docs
MIT License
1.09k stars 488 forks source link

expandAll() method is very slow with large objects,even if virtual scroll is true #938

Open poonamsinghlm opened 2 years ago

poonamsinghlm commented 2 years ago

expandAll() method is very slow with large objects,even if virtual scroll is true.Is there any way do performance improvement with large data.

rafaelceravolo commented 1 year ago

I found a workaround, setting the expandedNodeIds and calling update() worked and is very fast!

Here 's the code to add in your component that uses the tree:

@ViewChild(TreeComponent)
  treeComponent: TreeComponent;

...

 expandAll() {
    // the native expandAll() of the treeCOmponent is very slow. Setting the expandedNodeIds is much faster
    this.treeComponent.treeModel.expandedNodeIds = {};
    this.treeComponent.treeModel.doForAll((node) => {
      this.treeComponent.treeModel.expandedNodeIds[node.id] = true;
    });

    // doing the update without a timeout was expanding just the first level, with timeout, the whole tree is expanded!
    setTimeout(() => {
      this.treeComponent.treeModel.update();
    });
  }