Jstree How to change "New node" shortcut when creating a new node?

I am using the contextmenu plugin when creating a new node and then have my own function to create a new node using an ajax message.

$("#tree").jstree({
            //....

            "plugins": ["themes", "json_data", "crrm", "contextmenu", "dnd", "ui", "cookies"]
})
//...
.bind("create.jstree", function (e, data) {
             //...
             $.ajax({
                    type: "POST",
                    //...
                    });
});

      

I would like to change the default label "New node" to "New folder" when clicking "New". Any help would be appreciated.

+3


source to share


5 answers


Here you can change the context menu options

$("#tree").jstree({
"plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"],
"contextmenu": {
    "items": function ($node) {
        return {
            "Create": {
                "label": "New Folder",
                "action": function (obj) {
                    this.create(obj);
                }
            }
        };
    }
}
});

      

Update

You can find this part in jquery.jstree.js file



if(!js.data) { js.data = this._get_string("new_node"); }

      

change this part to

if(!js.data) { js.data = this._get_string("new folder"); }

      

+3


source


Here's how to change lines in jsTree v.3. Note that this is different from previous versions because the key is the text you want to change ( 'New node'

instead of new_node

):



$("#content_tree").jstree({
    core: {
        strings : {
            'New node': 'Your Text'
        }
    }
});

      

+11


source


According to the documentation, you just need to define a string parameter in your kernel settings.

For example:

        $("#content_tree").jstree({
            core: {
                animation: 100,
                strings : { loading : "Loading ...", new_node : "New folder" }
            },
            "plugins" : [ "themes", "html_data"]
        });

      

+1


source


Add a line after initializing the event create_node

data.node.text = 'My Custom Name';

      

Example:

$('#selector').jstree( ... ).on('create_node.jstree', function (e, data) {

   data.node.text = 'My Custom Name';

   ...

});

      

add

+1


source


Thank you for your help. I changed the new node to a new folder in the default jquery.jstree.js file and it worked. Thanks again.

$.jstree.plugin("core", {
        __init : function () {
            this.data.core.locked = false;
            this.data.core.to_open = this.get_settings().core.initially_open;
            this.data.core.to_load = this.get_settings().core.initially_load;
        },
        defaults : { 
            html_titles : false,
            animation   : 500,
            initially_open : [],
            initially_load : [],
            open_parents : true,
            notify_plugins : true,
            rtl         : false,
            load_open   : false,
            strings     : {
                loading     : "Loading ...",
                new_node    : "New folder",
                multiple_selection : "Multiple selection"
            }
        },

      

0


source







All Articles