extjs4中在右側的工具列實現執行個體

來源:互聯網
上載者:User

現在我們要實現放置在右側的工具列,這次我們直接在面板的代碼裡面寫,代碼如下:

 代碼如下 複製代碼

[Js]
    var panel = new Ext.Panel({
        renderTo: "div1",
        width: 600,
        height: 250,
        collapsible: true,
        layout: 'fit',
        title: '示範工具列',
        items: listView,
        tbar: tbar,
        bbar: bbar,
        rbar: [{
            iconCls: 'add16',
            tooltip: '按鈕1'
        },
            '-',
            {
                iconCls: 'add16',
                tooltip: {
                    text: '按鈕2',
                    anchor: 'left'
                }
            }, {
                iconCls: 'add16'
            }, {
                iconCls: 'add16'
            },
            '-',
            {
                iconCls: 'add16'
            }
        ]
    });


預覽下效果:

最後奉上完整的代碼:

 代碼如下 複製代碼

[Js]
Ext.onReady(function () {
    Ext.QuickTips.init();

    Ext.define('Datas', {
        extend: 'Ext.data.Model',
        fields: [
        { name: 'IntData', type: 'int' },
        { name: 'StringData', type: 'string' },
        { name: 'TimeData', type: 'date' }
       ],
        proxy: {
            type: 'ajax',
            url: 'Toolbar1Json',
            reader: {
                type: 'json',
                root: 'rows'
            }
        }
    });

    var store = new Ext.data.Store({
        model: 'Datas',
        sortInfo: { field: 'IntData', direction: 'DESC' },
        autoLoad: true
    });
    store.load();

    var listView = Ext.create('Ext.ListView', {
        store: store,
        multiSelect: true,
        emptyText: '當前沒有資料展示',
        reserveScrollOffset: true,
        columns: [{
            header: "IntData",
            dataIndex: 'IntData'
        }, {
            header: "StringData",
            dataIndex: 'StringData'
        }, {
            header: "TimeData",
            dataIndex: 'TimeData',
            align: 'right',
            xtype: 'datecolumn',
            format: 'm-d h:i a'
        }]
    });

    var filed1 = new Ext.form.Field();

    var tbar = Ext.create("Ext.Toolbar", {
        items: ['文字', "-", {
            xtype: "splitbutton",
            text: "按鈕"
        }, {
            text: "菜單",
            menu:
            {
                items: [
                    {
                        text: '選項1'
                    }, {
                        text: '選項2'
                    }, {
                        text: '選項3',
                        handler: function () {
                            Ext.Msg.alert("提示", "來自菜單的訊息");
                        }
                    }
                ]
            }
        }, "->", "關鍵字:", filed1, {
            text: "搜尋",
            handler: function () {
                store.load({ params: { keyword: filed1.getValue()} });
            }
        }
        ]
    });

    var bbar = Ext.create('Ext.toolbar.Toolbar', {
        layout: {
            overflowHandler: 'Menu'
        },
        items: ["溢出測試", "溢出測試", "溢出測試", "溢出測試", "溢出測試", "溢出測試", "溢出測試",
        "溢出測試", "溢出測試",
        {
            xtype: "button",
            text: "溢出按鈕",
            handler: function () {
                Ext.Msg.alert("提示", "工具列按鈕被點擊");
            }
        }, { text: "溢出按鈕", xtype: "splitbutton"}]
    });

    var panel = new Ext.Panel({
        renderTo: "div1",
        width: 600,
        height: 250,
        collapsible: true,
        layout: 'fit',
        title: '示範工具列',
        items: listView,
        tbar: tbar,
        bbar: bbar,
        rbar: [{
            iconCls: 'add16',
            tooltip: '按鈕1'
        },
            '-',
            {
                iconCls: 'add16',
                tooltip: {
                    text: '按鈕2',
                    anchor: 'left'
                }
            }, {
                iconCls: 'add16'
            }, {
                iconCls: 'add16'
            },
            '-',
            {
                iconCls: 'add16'
            }
        ]
    });


});

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.