How to redraw jstree tree with new data?

user2680139 picture user2680139 · Mar 15, 2014 · Viewed 30.9k times · Source

So, my question. I initialized my tree with some data:

$('#tree').jstree({
    'core' : {
        'data' : [
            'Simple root node',
            {
                'id' : 'node_2',
                'text' : 'Root node with options',
                'state' : { 'opened' : true, 'selected' : true },
                'children' : [ { 'text' : 'Child 1' }, 'Child 2']
            }
        ]
    });

But after some actions, I want to redraw tree with new data. I try to use refresh and redraw methods from API, but it unsuccessfully.

Can you give me advice, how to refresh tree (without destroy -> create new instance (it works, but it will affect the performance))?

Answer

faxiubite picture faxiubite · May 11, 2016

At version 3 you can reload the tree :

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