17

I have a problem with JsTree's contextmenu, how can I remove the default elements from the contextmenu like Create, Delete, Rename? I want to provide elements of my own, but the default elements are still at the contextmenu.

    "contextmenu" : {
                    "items" : {
                        "IsimVer" : {
                            "label" : "İsim Değiştir",
                            "action" : function (obj) { this.rename(obj); }
                        },
                        "Ekle" : {
                            "label" : "Ekle",
                            "action" : function (obj) { this.create(obj); }
                        },
                        "Sil" : {
                            "label" : "Sil",
                            "action" : function (obj) { this.remove(obj); }
                        }
}
LostMohican
  • 3,082
  • 7
  • 29
  • 38
  • What is problem with changing elements inside `items`to new values? [link](http://www.jstree.com/documentation/contextmenu) parent one is `key` and `label` will be label for context menu – Pradeep Dec 13 '11 at 15:24

4 Answers4

15

I had this issue a couple of days ago but haven't yet decided if this is a bug or a feature. It may be related to the order in which the plugins are loaded.

What worked for me was returning the items from a function:

"contextmenu" : {
    "items" : function ($node) {
        return {
            "IsimVer" : {
                "label" : "İsim Değiştir",
                "action" : function (obj) { this.rename(obj); }
            },
            "Ekle" : {
                "label" : "Ekle",
                "action" : function (obj) { this.create(obj); }
            },
            "Sil" : {
                "label" : "Sil",
                "action" : function (obj) { this.remove(obj); }
            }
        };
    }
}

After some searching it seems that the default behaviour is for your menu items to extend the defaults, so this is a feature. Unfortunately the documentation currently lacks the detail on this point.

contrebis
  • 1,287
  • 1
  • 11
  • 20
  • 2
    looks same but i figured that you have to do this : }, create : false, rename : false, remove : false, ccp: false in items object. – LostMohican Dec 14 '11 at 08:33
13

If you like to modify labels of existing items or remove a few, a simple solution like below will work

"contextmenu": {
   "items": function(node) {
           var defaultItems = $.jstree.defaults.contextmenu.items();
           defaultItems.create.label = "Ekle";
           delete defaultItems.ccp;
           return defaultItems;
        }
    }

This will set "Create" items label as "Ekle" and remove cut copy paste from default items.

Gorky
  • 1,393
  • 19
  • 21
6

Just set value to false in items object. For example, to disable edit (cut, copy, paste) menu try this:

contextmenu : {
    items : {
        "ccp" : false
    }
}
user570605
  • 738
  • 7
  • 9
3


Set ccp, create, rename, remove to false like this :

plugins : ["themes","json_data","ui","crrm", "hotkeys", "types", "contextmenu"],
contextmenu : {
    items : {
        "IsimVer" : {
            "label" : "IsimVer",
            "action" : function (obj) { alert("IsimVer"); }
        },
        "Ekle" : {
            "label" : "Ekle",
            "action" : function (obj) { alert("Ekle"); }
        },
        "Sil" : {
            "label" : "Sil",
            "action" : function (obj) { alert("tiga"); }
        },
        "ccp" : false,
        "create" : false,
        "rename" : false,
        "remove" : false
    }
}