How to auto height viewport child panels in it?

Pravin Mane picture Pravin Mane · Mar 23, 2013 · Viewed 10.9k times · Source

I am working in ExtJS4. I am getting stuck at a point where I want to auto height the east region of border layout. Actually my requirement is to automatically increase height of any region based on child elemtents content inside it. I tried a lot but I did not get solution for it. Please give me some suggestion.

In my code I am just testing a simple code containing 5 panels in east region, out of those four panels are displayed. The fifth panel is not displayed, how can I make it visible? I am just using a sample code for reference.

Here is my viewport code :

Ext.define('Am.view.Viewport', {
    extend: 'Ext.container.Viewport',
    layout: 'border',
    id:'viewportId',
    alias:'widget.Viewport',
    autoScroll:true,

       //        closable:true,
               items: [
                       {
                           region:'north',
                                       items:[
                                  {
                                      xtype:'panel',
                                      flex:.2,
                                      title:'north region',
                                      html:'<p>north region'
                                  }

                                  ]//end of items

                       },
                       {
                           region:'west',
                           id:'westId',
                           //margins:'0 5 5 5',
                           flex:.3,
                           //layout:'accordion',
                           items:[
                                              {
                                      title:'This day in a history',
                                      xtype:'Content'
                                  }

                                  ]//end if items
                       },// end of region west
                       {
                           //title:'center',
                           region:'center',
                           id:'centerId',
                           //html:'center region',
                           items:[
                                  ]//End of itmes
                       },// end of region center
                       {
                           region:'east',
                           id:'eastId',
                           //margins:'0 5 0 5',
                           flex:.3,
                           //layout:'accordion',
                           items:[
                                  {
                                      xtype:'panel',
                                      title:'panel1',
                                      html:'hi<br>hello<br>good<br><br><br><br><br>morning<br>nice<br>looking',
                                  },
                                  {
                                      xtype:'panel',
                                      title:'panel2',
                                      html:'hi<br>hello<br>good<br><br><br><br<br>noon<br>nice<br>looking',
                                  },
                                  {
                                      xtype:'panel',
                                      title:'panel3',
                                      html:'hi<br>hello<br>good<br><br><br><br><brafter noon<br>nice<br>looking'
                                  },
                                  {
                                      xtype:'panel',
                                      title:'panel4',
                                      html:'hi<br>hello<br>good<br><br><br><br><br><br><brnigth<br>nice<br>looking'
                                  },
                                  {
                                      xtype:'panel',
                                      title:'panel5',
                                      html:'good bye'
                                  },
                                  ]//end if items
                       },
                       {
                           //title:'South',
                           region:'south',
                           id:'southId',
                           items:[{
                                  xtype:'panel',
                                  title:"footer",
                                  html:'footer '
                           }]
                       },//mainMenu   // used mainMenu when you are using mainMenu variable
                       ]//end if items
});//End of view port

And here is my screen shot output : enter image description here

Child component panel5 is not displayed. How can I make it visible? How can I display all panels with this requirement? I want to make auto increase the size of east region based on panel contents.
Please give me some suggestion.

Answer

Izhaki picture Izhaki · Mar 24, 2013

To get a panel to autoresize based on its content

You should set its flex to 0, and make sure other panels have flex that is different from 0. So in the following code, the footer has flex: 0 and the center region has flex: 1; the footer will therefore resize based on its contents. Here's a working JsFiddle:

Ext.create('Ext.panel.Panel', {
    width: 500,
    height: 300,
    title: 'Border Layout',
    layout: 'border',
    items: [{
        title: 'Footer',
        region:'south',
        xtype: 'panel',
        margins: '5 0 0 5',
        flex: 0, // Notice this.
        id: 'footer',
        layout: {
            type: 'vbox',
            align : 'stretch',
            pack  : 'start',
        },
        items:[{
            title: '1',
            height: 50
        },{
            title: '2',
            height: 50                                   
        }]
    },{
        title: 'Center Region',
        flex: 1, // Notice this.
        region: 'center',
        xtype: 'panel',
        layout: 'fit',
        margins: '5 5 0 0'
    }],
    renderTo: Ext.getBody()
});

Ext.getCmp('footer').add({
    title: '3',
    height: 50                        
});

To get a panel of fixed size to scroll based on its content

Simply add autoScroll: true on the containers (the region panels).

Here's some working code, which you can see in action on this JsFiddle:

Ext.create('Ext.panel.Panel', {
    width: 500,
    height: 300,
    title: 'Border Layout',
    layout: 'border',
    items: [{
        title: 'West Region',
        region:'west',
        xtype: 'panel',
        margins: '5 0 0 5',
        width: 200,
        id: 'west-region-container',

        // Notice the next line
        autoScroll: true,
        layout: {
            type: 'vbox',
            align : 'stretch',
            pack  : 'start',
        },
        items:[{
            title: '1',
            height: 100
        },{
            title: '2',
            height: 100            
        },{
            title: '3',
            height: 100                        
        }]
    },{
        title: 'Center Region',
        region: 'center', 
        xtype: 'panel',
        layout: 'fit',
        margins: '5 5 0 0'
    }],
    renderTo: Ext.getBody()
});