1


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?

DanMan
  • 11,323
  • 4
  • 40
  • 61
harris
  • 47
  • 6
  • Why would you want to do that? – Layke Apr 04 '11 at 20:38
  • Problem is: First I need to select the tree node and then only my right click menu opens.If I directly right click on the tree node,I don't get the treenode scope.So when some node is selected and u right click on another treenode I get the popup menu for the selected node and not for the required node.Is there any solution to solve this problem? – harris Apr 05 '11 at 07:13

1 Answers1

0

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);
    }
}
Swapnil
  • 247
  • 1
  • 7