Unable to open right click menu when dojo tree node is not selected

712 Views Asked by At


I am using dojo 1.5. When I right click on dojo tree my right click pop up menu does not get created as first I need to select the treenode.
Is there any way of selecting a treenode when you right click on the dojo tree node?

1

There are 1 best solutions below

0
On

There is no out of the box way to do this, but you can achieve this by adding an event handler for mouse down

dojo.connect(this.tree, 'onMouseDown', lang.hitch(this,this.onTreeRightClick));

onTreeRightClick : function(event)
{
    if(event.button=="2"){
        var node = dijit.getEnclosingWidget(event.target);
        var nodes=this.tree.selectedNodes;
        if(nodes.indexOf(node)>-1)
            return;//if the node is already selected do not alter selected nodes.
        this.tree._setSelectedNodeAttr(node);
    }
}