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

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations