CirclonGroup / angular-tree-component

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

How to select all nodes, multiple nodes trought state manipulation? #884

Open Adam-Michalski opened 3 years ago

Adam-Michalski commented 3 years ago

First of all below implementations uses setIsActive(true); which every time its called emits activated event.

I have tried to use state manipulation to init values but unsuccessfully

How to select multiple nodes

my implementation is not optimal.

  setSelected(selected = []) {
    this.selected = selected;
    selected.forEach(node => {
      // need to find better way to select multiple nodes
      const toActivate: any = this.tree.treeModel.getNodeById(node.id || node);
      if (!toActivate.isActive) {
        toActivate.setIsActive(true);
      }
    });
  }

How to select all nodes

    // need to find better way to select all nodes
    this.zone.runOutsideAngular(() => {
      this.tree.treeModel.doForAll((node: TreeNode) => node.isActive !== true && node.setIsActive(true, true));
    });

AngularTreeNode is this lib TreeNode, it has alias cause I have the same name specified for my nodes