Refresh Selected Node of JSTree

12,368 views
Skip to first unread message

Amit Kumar

unread,
Jun 4, 2014, 10:45:11 AM6/4/14
to jst...@googlegroups.com
Hi All, 

I am opening a form on select of node, In form i can also update node name so i need to refresh the tree.
i am refreshing tree by "$("#demo4").jstree("refresh");"
demo4 is id of parent div so by this whole tree get refreshed but i want to refresh only selected node. :(

need to know how to do this from outside of JSTree itself. node is dynamic but i can create/know its id.
i tried these all but it is not working :(   (node_1 is id of selected node)
       $("#node_1").jstree("refresh", $(".jstree-clicked")); 
       $('#node_1').jstree('refresh'); 
       $("#demo4 node_1").jstree("refresh");

Thanks in advance :)

Ivan Bozhanov

unread,
Jun 4, 2014, 1:33:42 PM6/4/14
to jst...@googlegroups.com
You can use:
$("#demo4").jstree(true).refresh_node("node_1"); // this will reload the children of the node
If you want to update the node itself - refresh its parent:
$("#demo4").jstree(true).refresh_node($("#demo4").jstree(true).get_node("node_1").parent);

best regards,
Ivan

Amit Kumar

unread,
Jun 5, 2014, 6:23:53 AM6/5/14
to jst...@googlegroups.com
Thanks for reply Ivan,

I want to refresh node itself so i used your script like:

var newSelectId = $(jsTreeId).jstree("get_selected").attr("id"); // by this i am getting the id of selected node
$("#demo4").jstree(true).refresh_node($("#demo4").jstree(true).get_node(newSelectId).parent); // this is you script, in which i put selected node id

but using this i am getting exception like:
TypeError: $(...).jstree(...).get_node is not a function

I think i'm using some older version of jstree. i think this version is written by you only..:)
version is  jsTree 1.0-rc3 (Copyright (c) 2010 Ivan Bozhanov (vakata.com))

So, Ivan can tell me which method will be work in this version??

Ivan Bozhanov

unread,
Jun 5, 2014, 6:52:20 AM6/5/14
to jst...@googlegroups.com
Sorry, I am no longer supporting v.1, upgrade to v.3 (or search online for solutions to your problem, but I personally am no longer supporting v.1)
This is why the code I gave you will not work.

Best regards,
Ivan

Amit Kumar

unread,
Jun 5, 2014, 6:58:58 AM6/5/14
to jst...@googlegroups.com
Form where i can get v3, can you provide me actual link of v3.

i'm using only two files of jstree's v1 i.e. "jquery.jstree.js" and theme folder.

If i upgrade my code how much it affect and where i have to change, how much time it will take??

I don't have much time right now, can you suggest me what i should do right now??

Ivan Bozhanov

unread,
Jun 5, 2014, 10:44:42 AM6/5/14
to jst...@googlegroups.com
It is up to you. The changes from 1.0 to 3.0 are big and the API is different. www.jstree.com has all you need, but it is up to you to decide if you have the time to upgrade now.

Best regards,
Ivan

Amit Kumar

unread,
Jun 5, 2014, 11:15:25 AM6/5/14
to jst...@googlegroups.com
ok,
Thanks ivan for your support..:)

George Kj

unread,
May 7, 2015, 4:11:08 AM5/7/15
to jst...@googlegroups.com
Hi Ivan,
I am also facing same issue in refresh_node() method. I uses 3.0.0 version. how to 
change a node properties (like text,children) programmatically and then refresh it (not full tree refresh)
Thanks
George

Ivan Bozhanov

unread,
May 7, 2015, 5:14:02 AM5/7/15
to jst...@googlegroups.com, geow...@gmail.com
Well, you just change the variable and invoke refresh_node with the ID of the node you just updated.

Best regards,
Ivan

George Kj

unread,
May 8, 2015, 3:47:47 AM5/8/15
to jst...@googlegroups.com, geow...@gmail.com
Ivan,

Am not using the function callback method or AJAX for 'core.data' but using root node array method. 
In this case refresh_node is not handled i guess.
Sharing a jsfiddle sample which is showing an error in the console

George Kj

unread,
May 8, 2015, 4:05:48 AM5/8/15
to jst...@googlegroups.com
There is an error in previous fiddle. here is the corrected one http://jsfiddle.net/dmj49tjn/

George Kj

unread,
May 8, 2015, 4:06:44 AM5/8/15
to jst...@googlegroups.com
There is an error in previous fiddle. here is the corrected one http://jsfiddle.net/dmj49tjn/2/

Ivan Bozhanov

unread,
May 8, 2015, 4:08:12 AM5/8/15
to jst...@googlegroups.com, geow...@gmail.com
Here is your fixed fiddle: http://jsfiddle.net/dmj49tjn/3/

Best regards,
Ivan

George Kj

unread,
May 8, 2015, 5:46:39 AM5/8/15
to jst...@googlegroups.com, geow...@gmail.com
ok , but  i need to refresh the 'NodeD'  only which is the parent of newly added node .  is it possible ?

George Kj

unread,
May 8, 2015, 6:08:44 AM5/8/15
to jst...@googlegroups.com
Also is there any reference issue for root nodes in 3.0.0 ? i tried here in 3.0.0 and i can see that once the data callback is executed
for '#' , root nodes lost their children . 

Ivan Bozhanov

unread,
May 8, 2015, 8:17:49 AM5/8/15
to jst...@googlegroups.com, geow...@gmail.com
I do not remember any issues with root nodes, but to be safe - just use the latest version.
As for your question - your chosen data source does not allow for individual node refreshes, I believe the fiddle I provided should be enough, but use refresh(), not refresh_node(), since the fiddle will not handle it correctly.

Best regards,
Ivan

Newton Windt

unread,
Jul 14, 2015, 12:24:24 PM7/14/15
to jst...@googlegroups.com
Hi Ivan,

I'm trying to refresh a node using an id like the code you specified $("#demo4").jstree(true).refresh_node("node_1"); and its not working it does not refresh anything. When i run this code $('#jstree_demo_div').jstree("refresh"); it refreshes the whole tree. For example Im trying to rename a node but I do an async call to check if the node exists anywhere in the tree if it does than return node to original state which is what Im trying to do  by refreshing a specific node. When I refresh using this code $('#jstree_demo_div').jstree("refresh"); any node that changes is also refreshed back to its original state.

Regards Newton

Ivan Bozhanov

unread,
Jul 15, 2015, 3:59:28 PM7/15/15
to jst...@googlegroups.com, newto...@gmail.com
It all depends on your config and how you sync data to the server - I can not help you without seeing your config. Provided you are using lazy loading refreshing a specific node will work, but keep in mind that refreshes THE CHILDREN of the node, not the node itself - if you want to reload the node itself - refresh its parent.

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages