Search code examples
javascriptextjstabpanelsencha-architect

100% height TabPanel in Ext.js (using Sencha Architect)


I'm using Sencha Architect, and have yet to figure out how to get my TabPanel content to take up 100% of the container that the TabPanel lives in.

This is the code I'm using now:

Ext.define('MyApp.view.MyViewport', {
    extend: 'Ext.container.Viewport',

    layout: {
        type: 'border'
    },

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'container',
                    region: 'north',
                    height: 60
                },
                {
                    xtype: 'container',
                    region: 'center',
                    items: [
                        {
                            xtype: 'tabpanel',
                            activeTab: 0,
                            items: [
                                {
                                    xtype: 'panel',
                                    layout: {
                                        type: 'fit'
                                    },
                                    title: 'Tab 1',
                                    items: [
                                        {
                                            xtype: 'panel',
                                            title: 'My Panel'
                                        }
                                    ]
                                },
                                {
                                    xtype: 'panel',
                                    title: 'Tab 2'
                                },
                                {
                                    xtype: 'panel',
                                    title: 'Tab 3'
                                }
                            ]
                        }
                    ]
                }
            ]
        });

        me.callParent(arguments);
    }

});

I'm completely at a loss as to how to achieve this, and I haven't been able to find the answer in the Ext.js documentation.


Solution

  • Over-nesting. If you have a container without a layout, you're more often than not, doing something wrong:

    Ext.define('Foo', {
        extend: 'Ext.container.Viewport',
    
        layout: 'border',
    
        initComponent: function() {
            var me = this;
    
            Ext.applyIf(me, {
                items: [{
                    xtype: 'container',
                    region: 'north',
                    height: 60
                }, {
                    region: 'center',
                    xtype: 'tabpanel',
                    activeTab: 0,
                    items: [{
                        title: 'Tab 1',
                        html: 'Tab 1'
                    }, {
                        xtype: 'panel',
                        title: 'Tab 2',
                        html: 'Tab 2'
                    }, {
                        xtype: 'panel',
                        title: 'Tab 3',
                        html: 'Tab 3'
                    }]
                }]
            });
    
            me.callParent(arguments);
        }
    });
    
    Ext.onReady(function(){
        new Foo();
    });