John Mills
John Mills

Reputation: 10263

How can I refresh the contents of a jsTree?

I have loaded a jsTree with an AJAX call that returns JSON data. How can I refresh the tree so that it reloads its contents?

Upvotes: 62

Views: 93714

Answers (6)

Daniel
Daniel

Reputation: 1

my jsTree plug's version is 3.3.15

export function jsTreeUpdate(demo_id,treeData) {
  let instance = $('#' + demo_id).jstree(true);
  // set new data
  instance.settings.core.data = treeData;
  //important to refresh the tree, must set the second parameter to true
  instance.refresh(false,true);
}

The above code is the important function for update jsTree Node and show the corresponding state of new treeData.

enter image description here

Upvotes: 0

Kedron
Kedron

Reputation: 343

$('#treeId').data('jstree', false).empty().jstree(json);

Upvotes: 2

aecavac
aecavac

Reputation: 1036

At version 3 you can reload the tree :

$('#treeId').jstree(true).settings.core.data = newData;
$('#treeId').jstree(true).refresh();

Upvotes: 73

bydan
bydan

Reputation: 121

for jstree3 . I use destroy() function and again create tree running jstree() function

Upvotes: 12

Aigiz
Aigiz

Reputation: 381

var tree = jQuery.jstree._reference("#files");
tree.refresh();

or

var tree = jQuery.jstree._reference("#files");
var currentNode = tree._get_node(null, false);
var parentNode = tree._get_parent(currentNode);
tree.refresh(parentNode);

Upvotes: 26

John Mills
John Mills

Reputation: 10263

Turns out is is as simple as calling:

   tree.jstree("refresh");

Upvotes: 78

Related Questions