在extjs中添加一个组合框旁边的按钮

时间:2012-04-11 05:56:50

标签: extjs

我有一个面板,我有2个盒子。我需要在其中一个组合框旁边添加一个按钮。组合框和按钮都应该在同一行.Below是我的面板

filterPanel = new Ext.Panel({
        renderTo: document.body,
          bodyStyle: 'padding-top: 6px;',
    title: 'Filters',
        collapsible: true,
        collapsed: true,
        shadow: 'sides',
        width: 400,
        frame: true,
        floating: true,
        layout: 'form',
        labelWidth: 150,
        buttonAlign: 'center',
        items: [
            {
                xtype: 'combo',
                id: 'xFilter',
                width: 200,
                listWidth: 200,
                fieldLabel: 'Filter',
                store: filterStore,
                displayField:'filterDisp',
                valueField:'filterVal',
                typeAhead: true,
                editable: true,
                mode: 'local',
                forceSelection: true,
                triggerAction: 'all',
                selectOnFocus:false
            },{
                xtype: 'combo',
                id: 'xStatus',
                width: 200,
                listWidth: 200,
                fieldLabel: 'Status',
                store: statusStore,
                displayField:'statusDisp',
                valueField:'statusVal',
                typeAhead: true,
                editable: false,
                mode: 'local',
                forceSelection: true,
                triggerAction: 'all',
                selectOnFocus:false
            }
        ]
    });

我需要按钮与第一个组合框相邻,这样第一个组合和按钮都应该是同一行。 有人可以帮我这个吗?

提前致谢...

2 个答案:

答案 0 :(得分:3)

在ExtJS 4中,由于'compositefield'不再可用,您可以使用'fieldcontainer'代替。

var config = {
    xtype:'fieldcontainer',
    layout:'hbox',
    fieldLabel: 'Combobox',
    items:[{
        xtype: 'combo',
        flex:1
        //rest of combo config,
    },{
        xtype:'button',
        text: 'Add New',
        handler: function(){
            //add new record
        }
    }]
};

答案 1 :(得分:0)

尝试使用复合字段

{
    xtype: 'compositefield',
    labelWidth: 120
    items: [
        {
            xtype     : 'textfield',
            fieldLabel: 'Title',
            width     : 20
        },
        {
            xtype     : 'textfield',
            fieldLabel: 'First',
            flex      : 1
        },
        {
            xtype     : 'textfield',
            fieldLabel: 'Last',
            flex      : 1
        }
    ]
}

或使用hboxcolumn布局。