Hadi zamani
Hadi zamani

Reputation: 253

How to adjust ExtJS textfield width according to its container

I use ExtJS version 4.2.1, and I have a table layout.

     Ext.create('Ext.panel.Panel', {
            width: 1300,
            height: 700,
            title: 'Table Layout',
            layout: {
                type: 'table',
                columns: 3,
                tdAttrs:
                    {
                        width: 500,
                    }
            },
            items: [
                {
                    fieldLabel: 'Text1',
                    xtype: 'textfield',
                },
                {
                    fieldLabel: 'Text2',
                    xtype: 'textfield',
                },
                {
                    fieldLabel: 'Text3',
                    xtype: 'textfield',
                },
                {
                    fieldLabel: 'Text4',
                    xtype: 'textfield',
                },
                 {
                     fieldLabel: 'Text5',
                     xtype: 'textfield',
                 },
                {
                    fieldLabel: 'Text6',
                    xtype: 'textfield',
                }],
            renderTo: Ext.getBody()
        });

and the result is: enter image description here each column width is 500px and I want to each textfield's width adjust with its container. somehow a autoWidth,But it doesn't now.

Upvotes: 6

Views: 9261

Answers (1)

Darin Kolev
Darin Kolev

Reputation: 3411

Add width in percents to the textfields:

Ext.create('Ext.panel.Panel', {
    width: 1300,
    height: 700,
    title: 'Table Layout',
    layout: {
        type: 'table',
        columns: 3,
        tdAttrs: {
            width: 500,
        }
    },
    defaults: {
        width: '95%'
    },
    items: [
         // ...
    ],
    renderTo: Ext.getBody()
});

Upvotes: 7

Related Questions