user596502
user596502

Reputation: 427

add root node and make it editable

I use jsTree plugin to get a tree structure. I have a button that should add root node to the tree. I am able to add it but not edit it. As soon as i add it, it should be editable (the same way it happens while creating nodes from context menu).

The code snippet is:

$('#treeview').jstree({
    core: {
        check_callback: true,
        data: treeData,
    },
    plugins: [ "wholerow", "contextmenu", "ui" ],
}).on("ready.jstree", function(e, data) {
    data.instance.open_all();
});

// It adds root node but does not set it in edit mode. How can i set it in editable mode?
$('#addRootNode').click(function(){
    $("#treeview").jstree("create_node", null, null, "last", "createRootNode", true);
});

Upvotes: 2

Views: 3968

Answers (1)

vakata
vakata

Reputation: 3886

You can try this:

$("#treeview").jstree("create_node", null, null, "last", function (node) {
    createRootNode.call(this);
    this.edit(node);
});

Here is a demo: http://jsfiddle.net/DGAF4/510/

Upvotes: 3

Related Questions