PDA

View Full Version : contextmenu on div



mdissel
27 May 2008, 2:26 AM
On a single page i'm rendering several divs with a unique ID. When the user right clicks on one of these divs it should popup a (dynamic ajax based) contextmenu..

What is the most efficient way of setting this up?
- register a right click on every div that should have a popup
- register a right click on the document body and check if the element has some class / id ..

It's also possible that these divs are rendered inside a column in a grid....

Thanks

Marco

Animal
27 May 2008, 2:44 AM
If its going to be in generated elements, then a click handler on the outermost Element, and usage of the delegate option would be your best bet.

mdissel
27 May 2008, 3:38 AM
If its going to be in generated elements, then a click handler on the outermost Element, and usage of the delegate option would be your best bet.

so you're recommending to catch the click in the outermost element (containing, grids, tabs /etc. (all can hold a context sensitive menu option)?

what do you mean with the delegate option?


Thanks
Marco

Animal
27 May 2008, 4:45 AM
Use it as documented.

jay@moduscreate.com
27 May 2008, 5:47 AM
Ext.fly('your_div_id').on(<event here>, function_here);

You'll need to show the menu at the xy coordinates, which you can get from the event itself.

Animal
27 May 2008, 6:23 AM
Not forgetting {delegate: 'div.my-class'} to limit the event handler to only firing when the event was fired inside a <div> with the class "my-class".