PrimeNG Tree - select TreeNode programmatically

Chris S. picture Chris S. · Mar 1, 2017 · Viewed 11.6k times · Source

I am using the PrimeNG Tree component to enable the users to select some values based on a tree structure. The selected nodes will be later stored in a database and when the user visits the edit dialog again these nodes should be pre selected.

Is there any way to achieve this with the current PrimeNG version? Alternatively it would be nice if you can tell me another angular2 tree component which supports checkbox selection and pre-selection of nodes as well.

Answer

Aleksandr Petrovskij picture Aleksandr Petrovskij · Mar 1, 2017

In selectionMode="checkbox" selected nodes stored in [(selection)]="selectedNodesArray" property.

You can put values from database into selectedNodesArray and this nodes will be selected.