Michael Ela
Michael Ela

Reputation: 11

How to deselect child nodes in JSTree after the user selected some nodes?

I would like to deselect some selected nodes in JSTree based on the user selection. If the user selected 2 child nodes with similar category. I would like to programmatically deselect the 1st node the user selected.

Thanks in advance for the help. Hope you can help me figure out the solution.

Regards, Michael

Upvotes: 1

Views: 5257

Answers (1)

Nikolay Ermakov
Nikolay Ermakov

Reputation: 5061

You can place this testing into select_node event and see if you need to unselect something. E.g. the code below tests if there is more than one node selected and unselects the first one. Check demo - codepen.

.on('select_node.jstree', function(e, data){
      var countSelected = data.selected.length;
      if (countSelected>1) {
        data.instance.deselect_node( [ data.selected[0] ] );
      }
})

Upvotes: 1

Related Questions