Extjs - the center of the Panel form on a regular panel

I am using extjs and just trying to solve a simple problem: I have a fixed width form. I want to Center this form within a regular Ext.Panel. I am trying to achieve this "css-way" - setting the left and right margins to "auto".

But this does not work, it seems that the fields are simply ignored.

The code:

var curStateForm = new Ext.FormPanel({
    title:'test',
    width:300,
    bodyStyle:'margin:5px auto 0 auto',
    items: [edIst, edAdjust, edSumme]
});   


var testPanel = new Ext.Panel({
    width: '100%',
    frame:true,
    items: [curStateForm]
});  
+3
source share
7 answers

Have you seen this example ? See an example in the "custom layouts / center" section.

: Ext 3 . Ext 4 vbox , A1rPun.

+1

Ext 4

    layout: {
        type: 'vbox',
        align: 'center',
        pack: 'center'
    },
    items: [{
        title: 'Centered Panel',
        width: 200,
        height: 200
    }]
+16
    style: {
        marginLeft: 'auto',
        marginRight: 'auto'
    },
+3
source

I just did it with the panel

listeners: {
    afterlayout : function(container, layout, eOpts) {
    panel.center();
    }
}

Worked for me.

+2
source

In the panel:

bodyStyle: "padding: 15px;"  // may also be only padding-left/right
+1
source

For example, I use this layout:

Ext.layout.AbsoluteCenterLayout = Ext.extend(Ext.layout.ContainerLayout, {
    monitorResize:true,
    onLayout : function(ct, target){
        Ext.layout.AbsoluteCenterLayout.superclass.onLayout.call(this, ct, target);
        if(!this.container.collapsed){
            var sz = (Ext.isIE6 && Ext.isStrict && target.dom == document.body) ? target.getViewSize() : target.getStyleSize();
            this.setItemSize(this.activeItem || ct.items.itemAt(0), sz);
        }
    },
    setItemSize : function(item, size){
        if(item && size.height > 0){ // display none?
            formEl = item.getEl();
            var widthCenter = (size.width/2)-(formEl.getWidth()/2);
            var heightCenter = (size.height/2)-(formEl.getHeight()/2);
            formEl.setStyle({
                left: widthCenter+'px',
                top: heightCenter+'px',
                position: 'absolute',
            });
        }
    }
});
Ext.Container.LAYOUTS['absolutecenter'] = Ext.layout.AbsoluteCenterLayout;

My form:

    Viewport = new Ext.Viewport({
                renderTo: Ext.getBody(),
                layout: 'border',
                items: [{
                    region: 'center',
                    xtype: 'panel',
                    layout: 'absolutecenter',
                    baseCls: 'x-plain',
                    items:[{
                        id: 'form',
                        formId: 'admin-loginform',
                        xtype: 'form',
                        title: 'Authentication',
                        iconCls: 'admin-wnd-authentication',
                        frame: true,
                        autoHeight: true,
                        width: 270,
                        defaultType: 'textfield',
                        labelAlign: 'right',
...
+1
source

Try the following in the panel:

style: {
    "margin-left": "auto",
            "margin-right": "auto"
       }, 
0
source

Source: https://habr.com/ru/post/1746534/


All Articles