-
6 Aug 2012 8:21 AM #1
Where to place contextmenu?
Where to place contextmenu?
Hi,
I have a tree panel which shall show a context menu. When I place the menu as child of the tree panel Ext.getCmp or this.getComponent does not find the menu. Is this a bug?
Thank you
-
6 Aug 2012 8:30 AM #2
The approach I have used is to build a context menu on the fly and make it show at the point where the mouse was clicked. In your itemcontextmenu event, add some code like this:
Then define those functions elsewhere in your controller:Code:e.stopEvent(); var ctxMenu = new Ext.menu.Menu({ items: [ { itemId : 'newSomething', handler : this.onNewSomething }, { itemId : 'editSomething', handler : this.onEditSomething }, { itemId : 'deleteSomething', handler : this.onDeleteSomething } ] }); var newSomethingItem = ctxMenu.getComponent('newSomething'); var editSomethingItem = ctxMenu.getComponent('editSomething'); var deleteSomethingItem = ctxMenu.getComponent('closeSomething'); newSomethingItem.setText('New Something...'); editSomethingItem.setText('Edit Something...'); deleteSomethingItem.setText('Delete Something...'); ctxMenu.showAt(e.getXY());
Code:onNewSomething:function() { ... } onEditSomething:function() { ... } onDeleteSomething:function() { ... }
-
6 Aug 2012 8:43 AM #3
I'd recommend creating a top level menu as a subclass and then using it as proposed by billtricarico above.
For example drag out a Menu, put some menu items in it...
then put a subscription to the contextnode event and do something like:
Code:e.stopEvent(); if (!this.menu) { this.menu = Ext.create('MyApp.view.MyMenu'); } this.menu.showAt(e.getXY());Aaron Conran
@aconran
Sencha Architect Development Team
-
6 Aug 2012 8:44 AM #4
OK; this works of course. But I want to create the view completely with SA not by code. I have placed it now as top level component and marked it as floating. This works. But it is not very intuitive - the contextmenu should be placeable as child of the component where it is used. Why can't I do this?
-
6 Aug 2012 8:46 AM #5
-
6 Aug 2012 8:48 AM #6
We have yet to add any convenience mechanism for marking something as a contextmenu. A lot of times you will want additional custom code, for example conditionally showing a different menu based off of the node clicked on, etc
We are working on making Architect further from the code so that you can do more and more without touching the code.Aaron Conran
@aconran
Sencha Architect Development Team
-
6 Aug 2012 9:01 AM #7


Reply With Quote