Ext.menu.Menu() : How to get the width of the menu (needed to display it with offset)

StackOverflow https://stackoverflow.com/questions/7805223

  •  25-10-2019
  •  | 
  •  

سؤال

First of all I'm using ext-3.3.1

I built a context menu using Ext.menu.Menu() and populated it with items like this:

menu.addMenuItem({
    text : TaskGeneralBaseds[i].getAttribute("Name"),
    templateTypeID : templateTypeID,
    taskType : taskType,
    scope : this,
    listeners : {
           click : {
             fn : this.extAddTaskClicked
       }
    },      
    icon:g ? g : null
    });

and than i display the menu like this

var left = window.event.clientX;
var top = window.event.clientY;

menu.showAt([left,top]);

now the thing is that i want to display it with offset as if it was displayed from right to left and not from left to right (I already took care of all the other RTL issues) so if i had the width of the menu i could do something like this:

var menuWidth = menu.width;// how can i really get the width?
var left = window.event.clientX-menuWidth ;

var top = window.event.clientY;

menu.showAt([left,top]);

Any ideas?

Thanks ahead!

Daniel.

هل كانت مفيدة؟

المحلول

Show the menu (so it will be rendered), get its width and then relocate:

menu.showAt(0,0);    
var menuWidth = menu.width;// how can i really get the width?
var left = window.event.clientX-menuWidth ;
var top = window.event.clientY;
menu.setPosition(left,top);

Or use a fixed config width.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top