How can I refresh the contents of a jsTree?

JqueryJstree

Jquery Problem Overview


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?

Jquery Solutions


Solution 1 - Jquery

Turns out is is as simple as calling:

   tree.jstree("refresh");

Solution 2 - Jquery

At version 3 you can reload the tree :

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

Solution 3 - Jquery

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);

Solution 4 - Jquery

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

Solution 5 - Jquery

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn MillsView Question on Stackoverflow
Solution 1 - JqueryJohn MillsView Answer on Stackoverflow
Solution 2 - JqueryaecavacView Answer on Stackoverflow
Solution 3 - JqueryAigizView Answer on Stackoverflow
Solution 4 - JquerybydanView Answer on Stackoverflow
Solution 5 - JqueryKedronView Answer on Stackoverflow