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

select checkbox manually #790

Closed neo1380 closed 4 years ago

neo1380 commented 4 years ago

I am using angular-tree-component and i am trying to select a checkbox manually. i have used

const node = treeModel.getNodeBy(node.uuid)
node.setIsSelected(true)

Is there any other recommended way to select a checkbox ? Also, the above selection is happening only when i pass node.uuid., if i pass node.id then it throws an error.

mimarox commented 4 years ago

I'd like to be able to specify a 'selected' property of type boolean on my nodes and get that evaluated correctly. If I replace the entire hierarchy of nodes with changes in the selected states of my nodes, I'd like the tree to reflect those changes. And an extra nice feature would be if the tree expanded all nodes to the selected nodes automatically.

adamkleingit commented 4 years ago

@neo1380 You should use getNodeById(node.id).

@mimarox The tree state is saved separately from the nodes by design. This way you can refresh the nodes state from the server and not lose UI state, persist tree state to localstorage, etc. So you can bind to [(state)] and achieve what you are looking for: https://angular2-tree.readme.io/docs/save-restore