views:

594

answers:

3

I'm trying to get the browser context menu to work inside a dojox.grid.DataGrid. When I right-click on the grid now, nothing happens. I tried overriding onCellContextMenu, onRowContextMenu, doContextMenu, and oncontextmenu with empty functions on the grid instance, but that didn't work. The method onCellContextMenu is called on a right-click, but it still doesn't show a context menu. I think the event is being stopped at another level, but I'm not sure where to look.

The grid has a list of links, and I want users to be able to right click on links so they can open them in a new tab. I know that I can make a custom context menu to provide that functionality, but I'd like to know how to disable this behavior in the future.

A: 

I know it's not exactly the solution you want for displaying the context menu, but have you tried telling your users to Ctrl-leftClick on those links rather right-click to display the context menu ?

Philippe
Yeah, that's where we are now, but it's not a good solution.
Alex
A: 

You need to create a dijit.menu in a div and set its display to none. Here's an example where the context menu and grid are contained in a dijit ContentPane:

<div dojoType="dijit.layout.ContentPane" title="MyGrid">
    <div id="myGridContainer" style="width:100%;height:100%"></div>
    <div id="myGridContextMenu" dojoType="dijit.Menu" style="display: none;">
        <div dojoType="dijit.MenuItem" id="myGridContextMenu.delete" onClick="deleteItem">Delete</div>
    </div>
</div>

You will also need to connect the menu to your grid when you create it:

var myGrid = new dojox.grid.DataGrid({ ..., onRowContextMenu: myGridcontextMenu },...);
Tony Lenzi
I can't get this to work, it still doesn't show a context menu.
Alex
I think I may have misunderstood your question. You want the Firefox/chrome/IE menu to show up with context, as it would on an image for example? Rather than one you hook in. So treat it just like another link on the page?
Tony Lenzi