jsTree "create_node" really not working

Catalin picture Catalin · Jul 4, 2012 · Viewed 15k times · Source

I am trying to dynamically add a new node in my jsTree container. It is not working at all. I don't know what i am missing.

jsfiddle example

$("#tree").jstree({
    core: {
        "animation": 0
    },
    "html_data": {},
    "themes": {
        "icons": false
    },
    "search": {
        "case_insensitive": true,
        "show_only_matches": true
    },
    "plugins": ["themes", "html_data", "search"]
});

$("#tree").jstree("create_node", $("node_1"), "after", { "data": "Hello World" });

html:

<div id="tree">
    <ul>
        <li id="node1"><a>Hello</a></li>
    </ul>
</div>

Answer

Pramod Alagambhat picture Pramod Alagambhat · Apr 2, 2014

set 'check_callback' : true, otherwise all operations like create, rename are prevented. like so:

        this.treeDiv.jstree(
                {

                    'core' : {
                        'check_callback': true,
                        'data' : {
                            'url' : function (node) {
                            return 'ajax_roots.json';
                            },
                            'data' : function (node) {}
                            }
                    },
                    "search" : {
                        "fuzzy" : false,
                        "show_only_matches": true,
                        "close_opened_onclear" : true
                    },
                    "plugins" : ["search", "sort", "json_data"]
                });