Skip to Content

Handle right click event on tree.

Hello, I currently have a tree which fires onSelect when its items left clicked. However, I also want to make it so that when the items are right clicked, a separate function is fired.

This is the XML layout of my tree:

<Tree
    id="myTree"
    selectionChange="onSelect"
    mode="SingleSelectMaster"
    toggleOpenState="onToggle"
    items="{path: 'data>/elements'}">
<StandardTreeItem 
    title="{data>Name}"
    icon="{data>Ref}"
</Tree>

I have tried following this fiddle(http://jsfiddle.net/V3sWc/) and adding a right click by placing

$('#myTree").on('contextmenu', function(){
    alert('you right clicked! congrats.');
    return false;
});

inside of the controller's onInit but it never gets called.

How do I create a right click even for the tree?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jun 13, 2019 at 02:43 AM

    Hi Betty,

    Add the following code in the onInit function:

    var oTree = this.byId("myTree");

    oTree.attachBrowserEvent("contextmenu", function(event){

    alert("right clicked");

    });

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.