Donate

Collapse Or Expand A jsTree Node Programmatically

Good day all!
Here's a snippet to collapse or exand a jstree node programmatically on page load based on the node id. The code below will collapse if node id is '45' while other nodes remain open.
$('#TreeRoles').bind('ready.jstree', function (e, data) {
 var $tree = $(this);
 
 $($tree.jstree().get_json($tree, {
  flat: true
 })).each(function (index, value) {
  var node = $tree.jstree().get_node(this.id);
  if (node.id === "45") {
   $tree.jstree().close_node({ "id": node.id });
  }
  else {
   $tree.jstree().open_node({ "id": node.id });
  }
 });
});  

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input