Angular-tree-component: get selected nodes (checkbox)

Created on 29 Dec 2017  路  5Comments  路  Source: CirclonGroup/angular-tree-component

Hi, i tried get the selected (checkbox) nodes but unsuccessfully..

utilizing the attribute"activeNodes"
https://github.com/500tech/angular-tree-component/blob/master/lib/defs/api.ts#L458

the return is empty array...

any idea of the problem?

Most helpful comment

You could use the following to subscribe to state changes.

  ngAfterViewInit() {
     this.treeComponent.treeModel.subscribeToState((state: any) { // ITreeState does not contain selectedLeafNodeIds

      console.log(state);
      console.log(this.treeComponent.treeModel.selectedLeafNodeIds);

      // drop the unwanted prototypes
      const selected = Object.assign({}, this.treeComponent.treeModel.selectedLeafNodeIds);
      console.log(selected);
    });
}

All 5 comments

I do not know if it is the best solution, but I used it that way to capture the ids of the selected nodes
Object.keys(tree.treeModel.selectedLeafNodeIds.$mobx.target)

@filipemansano what about when you uncheck some nodes? I came across this same decision trying to get checked leafs but when I uncheck nodes it doesn't refresh selectedLeafNodeIds, just when checking it is being refreshed...

@areisyus I could not find a satisfactory solution, so I created my own tri-state checkbox system

https://plnkr.co/edit/L6YHxOtI55lf1IlB6rJt?p=preview

You could use the following to subscribe to state changes.

  ngAfterViewInit() {
     this.treeComponent.treeModel.subscribeToState((state: any) { // ITreeState does not contain selectedLeafNodeIds

      console.log(state);
      console.log(this.treeComponent.treeModel.selectedLeafNodeIds);

      // drop the unwanted prototypes
      const selected = Object.assign({}, this.treeComponent.treeModel.selectedLeafNodeIds);
      console.log(selected);
    });
}

Closing this issue due to inactivity. Please open a new issue if the problem still exists.

Was this page helpful?
0 / 5 - 0 ratings