-
4 Sep 2008 8:46 PM #1
How to add menus to a button manually
How to add menus to a button manually
The example in document like this:
But I want to add menus to button manually, like:HTML Code:var btn1=new Ext.Button({ text:"File", menu:[ {text:"Open"}, {text:"Save"}, {text:"Close"}]});
of course,addMenu method is not exist, how do I can implement this?HTML Code:var btn1=new Ext.Button({text:"File"}); btn1.addMenu(...);
Thanks.
-
4 Sep 2008 9:00 PM #2
Untested, but give this a go:
Code:Ext.override(Ext.Button, { initComponent: function() { Ext.Button.superclass.initComponent.call(this); this.addEvents( "click", "toggle", 'mouseover', 'mouseout', 'menushow', 'menuhide', 'menutriggerover', 'menutriggerout' ); if (this.menu) { var m = this.menu; delete this.menu; this.setMenu(m); } if (typeof this.toggleGroup === 'string') this.enableToggle = true; }, setMenu: function(menu) { var hasMenu = (this.menu != null); this.menu = Ext.menu.MenuMgr.get(menu); if (this.rendered && !hasMenu) { this.el.child(this.menuClassTarget).addClass('x-btn-with-menu'); this.menu.on("show", this.onMenuShow, this); this.menu.on("hide", this.onMenuHide, this); } }, clearMenu: function(destroy) { if (this.rendered) { this.el.child(this.menuClassTarget).removeClass('x-btn-with-menu'); this.menu.un('show', this.onMenuShow, this); this.menu.un('hide', this.onMenuHide, this); } if (destroy) Ext.destroy(this.menu); this.menu = null; } } );Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
1 Apr 2013 4:16 AM #3
Error when applying above code
Error when applying above code
Did the Same but getting below error:
PHP Code:TypeError: this.el.child(...) is null
[Break On This Error]
this.el.child(this.menuClassTarget).addClass('x-btn-with-menu');
Code:var manageColumnsButton = Ext.override(Ext.Button, {icon : 'images/manage_columns.png', id:'manageColumnsButton', initComponent: function() { Ext.Button.superclass.initComponent.call(this); this.addEvents( "click", "toggle", 'mouseover', 'mouseout', 'menushow', 'menuhide', 'menutriggerover', 'menutriggerout' ); if (this.menu) { var m = this.menu; delete this.menu; this.setMenu(m); } if (typeof this.toggleGroup === 'string') this.enableToggle = true; }, setMenu: function(menu) { var hasMenu = (this.menu != null); this.menu = Ext.menu.MenuMgr.get(menu); if (this.rendered && !hasMenu) { this.el.child(this.menuClassTarget).addClass('x-btn-with-menu'); this.menu.on("show", this.onMenuShow, this); this.menu.on("hide", this.onMenuHide, this); } }, clearMenu: function(destroy) { if (this.rendered) { this.el.child(this.menuClassTarget).removeClass('x-btn-with-menu'); this.menu.un('show', this.onMenuShow, this); this.menu.un('hide', this.onMenuHide, this); } if (destroy) Ext.destroy(this.menu); this.menu = null; } } );


Reply With Quote