TheDude
TheDude

Reputation: 1531

Renaming a tree node dynamically outside of contextmenu in jstree

I use the code below to successfully create a new tree node in jstree outside of contextmenu. My question is how can you dynamically RENAME the text in a tree node in a similar manner outside of the contextmenu? Is there a .jstree("rename" ....) function that can be called to accomplish this? Much appreciated!

$("#RequirementsTree").jstree("create", null, "last", {"data" : "new_node_text",
                  "state" : "open",
                  "attr" :  { "id" : "new_node_id", "name" : "requirement" }, 
 });

I've tried the following:

        .bind("select_node.jstree", function(event, data) {
            ReqNode = data.rslt;

 $("#RequirementsTree").rename_node(ReqNode, "test");

That didn't work, however. Is there something I'm doing wrong?

Upvotes: 1

Views: 8024

Answers (5)

shifu.zheng
shifu.zheng

Reputation: 711

The following sentence works:
$("#demo1").jstree('set_text', node , text);

Upvotes: 0

Dimitri
Dimitri

Reputation: 633

There's decision: https://groups.google.com/forum/#!topic/jstree/cq9wzW9Ia3s

Shortly, by default jsTree prevents any changes in his tree, so you have to enable that:

$('#YourJSTree').jstree({ core: { check_callback: 'true' }, [...]

Upvotes: 0

Laguna
Laguna

Reputation: 3876

I'm using jsTree 1.0-rc3 version. The syntax below worked for me:

 $('#companyFields_tree').jstree('rename_node', '#0', 'testNewName' );

Upvotes: 1

TheDude
TheDude

Reputation: 1531

The below suggestion by Mortalus didn't work for me. Although it's my preference to stay within the confines of jstree specific code, I came up with a sort of jquery hack to get around the built-in "rename_node" and "set_text" methods since they weren't working for me. I thought I'd post my answer here in case others have the same issue:

   $(Node).find("a").text("the_new_text_for_the_node_you_want_to_rename");

This works for me. It basically grabs the anchor element below the li and sets the text for it.

Upvotes: 0

Mortalus
Mortalus

Reputation: 10712

This should work for you:

$("#demo1").jstree('set_text', [node , text] );
$("#demo1").jstree('rename_node', [node , text] );

JSTree Core Documentation...

how-can-i-rename-a-jstree-node

Upvotes: 2

Related Questions