PDA

View Full Version : Showing Ext.Menu at a particular mouse position



mrkadakia
24 Jul 2009, 10:32 AM
Hi all -
I am using the following JavaScript function to retrieve the mouse position:


function getMouseposition(evt) {
var mousepos = {};
mousepos.posx = 0;
mousepos.posy = 0;

if (!evt) var evt = window.event;

if (evt.pageX || evt.pageY) {
mousepos.posx = evt.pageX;
mousepos.posy = evt.pageY;
} else if (evt.clientX || evt.clientY) {
mousepos.posx = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
mousepos.posy = evt.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
return mousepos;
}When I use the above return object to set the X and Y properties of an Ext.Window object, it works perfect:


var win = new Ext.Window({
// Other details
x: clickedMousepos.posx,
y: clickedMousepos.posy
});
win.show();But, when I use the above return object to set the X and properties of an Ext.Menu, the menu does not appear at the correct position:


var blockMenu = new Ext.menu.Menu({
id: 'blockMenu',
style: {
overflow: 'visible'
},
items: [
{
text: 'Open'
},{
text: 'Edit'
},{
text: 'Delete'
}
]
});

blockMenu.showAt([clickedMousepos.posx, clickedMousepos.posy])

How do I resolve this issue?

Thanks in advance.

28 Jul 2009, 4:57 AM
showAt works as expected for me. does clickedMousepos.pos<x || y> have valid integer values?

28 Jul 2009, 4:58 AM
btw, what do you mean by "correct position"?

is it completely off??

mrkadakia
28 Jul 2009, 6:11 AM
[email protected],
Thanks for the response.

What I found is that when I set the X and Y property of a Ext.Window object to the values returned by the function, its position is determined with respect to the panel where the Ext.Window needs to be rendered.

In case of Ext.Menu, when I set the X and Y property to the values returned by the function, its position is determined with respect to the entire page in itself (i.e. the entire viewport). The Ext.Menu is also being rendered to the same panel as Ext.Window.

How do I change this behavior? I want the Ext.Menu to open up with respect to the panel to which it is being rendered.

Any inputs will be appreciated.