将工具栏添加到网格 - Extjs

时间:2013-07-25 14:47:07

标签: extjs grid panel toolbar

我在这里有以下网格:

Ext.define('AM.view.user.List', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.userlist',
    title: 'All Users',
    store: 'Users',

    initComponent: function () {
        this.columns = [{
            header: 'Name',
            dataIndex: 'name',
            flex: 4
        }, {
            header: 'User ID',
            dataIndex: 'user_id',
            flex: 1
        }, {
            header: 'Address',
            dataIndex: 'address',
            flex: 3
        }, {
            header: 'Age',
            dataIndex: 'agee',
            flex: 5
        }];

        this.callParent(arguments);
    }
});

可以将工具栏添加到此网格的底部,还是只能将它们添加到面板?

另外,如何将普通文本放在工具栏而不是按钮中?

3 个答案:

答案 0 :(得分:15)

是网格面板继承Ext.grid.Panel,您应该可以添加:

dockedItems: [{
    xtype: 'toolbar',
    dock: 'top',
    items: [{
        xtype: 'button',
        text: 'Left Button'
    }, {
        xtype: 'tbfill'
    }, {
        xtype: 'button',
        text: 'Right Button'
    }]
}]

答案 1 :(得分:2)

任何具有Docked布局的组件都可以停靠工具栏。由于Ext.grid.Panel延伸Ext.panel.Panel,您可以停靠它。请参阅bbar config:http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.panel.Panel-cfg-bbar

您可以将文本项添加到工具栏的items

,从而将文本项添加到工具栏中
{ xtype: 'tbtext', text: 'My Text' }

此处的文档:http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.toolbar.TextItem

答案 2 :(得分:2)

或者,您也可以使用“bbar[...]”添加按钮,该按钮等同于

dockedItems: [{
    xtype: 'toolbar',
    dock: 'bottom',
    items: [
        { xtype: 'button', text: 'Button 1' }
    ]
}]

这允许您在gridpanel底部添加所有其他按钮属性允许使用的按钮。

示例代码在这里:

 bbar: [
      { xtype: 'button', text: 'Button 1' },
      { xtype: 'button', text: 'Button 2' }
    ]

有关详细信息,请参阅文档:http://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.panel.Panel-cfg-bbar

相关问题