Toolbar items added/inserted into Ext.ToolBar aren't showing on the page

I have a custom component that extends a panel. The panel has a top tool bar with a basic config. I want to be able to add items to the panel dynamically after it has been created.

Those items should always come at the end of the main set of menu items and before the filler that pushes the logout button to the far right, so I wrote the insertMenuItem function to grab the position of the "shunt" (the tbfill) item and insert the new toolbar item at this location. If it doesn't find the "shunt", because its been overridden, it just adds to the end of the toolbar.

This seems to work just great. If I look at the "live" contentPanel I can see the inserted menu item. The problem come with getting it to display. Now I suspect that this is a scoping issue, I'm just not sure what, where, when, how.... :|

I've tried this.doLayout(), topToolbar.doLayout() in the function I've got a doLayout() on the contentPanel object after calling my function, but none of them seem to help.


Below is my extended Panel class. Thanks in advance for your help


SOM.ux.contentPanel = Ext.extend(Ext.Panel, {
    ,initComponent:function() {
        var config = {
            ,contentEl : Ext.get('som-body')
                    xtype : 'button',
                    text: 'Dashboard',
                    handler: function(){
                        document.location.href = '/'
                },{itemId:'shunt',xtype: 'tbfill'},{
                    xtype : 'button',
                    text: 'Logout',
                    handler: function(){
                        document.location.href = '/admin.login.doLogout'
                        xtype : 'tbbutton',
                        text: 'Message',
                        scope: this,
                        handler: function(){

        }; // end of config
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        SOM.ux.contentPanel.superclass.initComponent.apply(this, arguments);
    ,afterRender: function(){
    ,onDispatchMessage: function(subject,message) {
        if (message.action) {
        console.log('contentpanel doDispatch',subject,message);
    ,insertMenuItem: function(itemObj){
        var topToolbar = this.getTopToolbar();
        var aItems = topToolbar.items;
        var insertPos = aItems.indexOfKey('shunt');
        if (insertPos) {
            console.log('using insert');
        } else {
            console.log('using add');


Make sure you are calling insertMenuItem after the toolbar has rendered. Is itemObj (the param) an Ext.Toolbar.Item config?

The following works:

var tb = new Ext.Toolbar({
    items : [{text : 'wtf'}]

new Ext.Window({
    width : 300,
    height : 100,
    tbar : tb

(function() {
    tb.add({text:'new btn'});

To add to jonathan's comment, only call doLayout after it's rendered.

Need Your Help

how to customise UITableView?

ios ios4 xcode4 uitableview

How to add image and texts as shown in the below snapshots?I am already using navigation controller in my application, so is there any problem in including UITableView controller as a new navigated...

Web2py: Can you password protect a page?


The specific functionality I'm looking for:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.