Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align components in the center in a Panel: EXT JS

I am new to ext JS and I am tryin gto place 3 components in a FormPanel but I don't know ho wto align them in the center.

Here is my code

var durationForm = new Ext.FormPanel({
        border      : false,
        labelAlign  : 'top',
        frame       : true,
        bodyStyle   : 'padding-left:475px;',
        items: [{
          items: [{
            rowWidth    : .5,
            layout      :'column',
                items:[{
                    columnWidth     : .13,
                    layout          : 'form',
                    items           : [getNewLabel('<br/><font size="3">Duration: </font>')]
                },{
                    columnWidth     : .20,
                    layout          : 'form',
                    items           : [fromDate()]
                },{
                    columnWidth     : .17,
                    layout          : 'form',
                    items           : [toDate()]
                }]
          }]
        }]
    });

    durationForm.render(Ext.getBody());

This shows output like this enter image description here

But I want components to be align in the center of the panel. Anyone know how to do it?

like image 642
Ajan Avatar asked Dec 22 '22 11:12

Ajan


2 Answers

I have solved this problem by using 'table' layout:

{
    layout : 'fit', // parent panel should have 'fit' layout 
    items : [ // and only one item
        {
            xtype : 'panel',
            border : false, // optional
            layout : {
                type : 'table',
                columns : 1, 
                tableAttrs : {
                    style : {
                        width : '100%',
                        height : '100%'                                 
                    }
                },
                tdAttrs : {
                    align : 'center',
                    valign : 'middle',
                },
            },
            items : [ // a single container for nested components
                {
                    xtype : 'panel',
                    layout : 'fit',
                    cellId : 'cell_id', // this one will be placed as id for TD
                    items : [
                         {}, {}, {} // nested components
                    ]
                }
            ]
        }
    ]
}
like image 165
DMS Avatar answered Jan 12 '23 02:01

DMS



{
//...
  layout:'hbox',
  layoutConfig: {
    padding:'5',
    pack:'center',
    align:'middle'
  },
  items:[{
       columnWidth     : .13,
       layout          : 'form',
       items           : [getNewLabel(...)]
     },{
       columnWidth     : .20,
       layout          : 'form',
       items           : [fromDate()]
     },{
       columnWidth     : .17,
       layout          : 'form',
       items           : [toDate()]
  }]
//...
}

See this

like image 32
Amol Katdare Avatar answered Jan 12 '23 02:01

Amol Katdare