EXTJS4自學手冊——頁面控制項(表格的外掛程式)

來源:互聯網
上載者:User

一、Ext.grid.plugin.CellEditing

說明:編輯表格儲存格外掛程式

例子:

定義store:

            var store = Ext.create("Ext.data.ArrayStore", {                fields: ['id', 'name', 'age', 'address'],                data: [                    [1, 'aaa', '23', '江津'],                    [2, 'bbb', '34', '北碚'],                    [3, 'ccc', '33', '江津'],                    [4, 'ddd', '54', '杭州'],                    [4, 'eee', '24', '北碚']                    ]            });

定義表格:

Ext.create('Ext.grid.Panel', {                title: '學習grid控制項',                store: store,                forceFit: true,                renderTo: Ext.getBody(),                //儲存格選擇模式                selType: 'cellmodel',                plugins: [                //編輯儲存格外掛程式                    Ext.create("Ext.grid.plugin.CellEditing", {                        //雙擊開始編輯                        clicksToEdit: 2                    })                ],                columns: [{                    text: '姓名', dataIndex: 'name',                    //定義編輯狀態時的控制項,沒有定義不能編輯                    editor: {                        xtype: 'textfield',                        //是否可以為空白                        allowBlank: false                    }                }, {                    text: '年齡', dataIndex: 'age',                    editor: {                        xtype: 'datefield'                    }                }]            });        });

執行結果:

二、Ext.grid.plugin.RowEditing

說明:行編輯外掛程式:

例子:

定義store同上

定義表格:

Ext.create('Ext.grid.Panel', {                title: '學習grid控制項',                store: store,                renderTo: Ext.getBody(),                //儲存格選擇模式                selType: 'rowmodel',                plugins: [                //編輯儲存格外掛程式                    Ext.create("Ext.grid.plugin.RowEditing", {                        //雙擊開始編輯                        clicksToEdit: 2                    })                ],                columns: [{                    text: '姓名', dataIndex: 'name',                    //定義編輯狀態時的控制項,沒有定義不能編輯                    editor: {                        xtype: 'textfield',                        //是否可以為空白                        allowBlank: false                    }                }, {                    text: '年齡', dataIndex: 'age',                    editor: {                        xtype: 'datefield'                    }                }]            });

執行結果:

三、同步資料到後台伺服器

說明:通過表格的getStore()方法擷取表格的store容器,然後通過store容器的sync方法,同步資料

例子:

定義store:

 var store = Ext.create("Ext.data.ArrayStore", {                fields: ['name', 'age'],                               proxy: {                    type: 'sessionstorage',                    id: 'myInfo'                }            });            store.add([['aaa', '13'], ['bbb', '23']])

定義表格:

 Ext.create('Ext.grid.Panel', {                title: '學習grid控制項',                store: store,                renderTo: Ext.getBody(),                //儲存格選擇模式                selType: 'rowmodel',                plugins: [                //編輯儲存格外掛程式                    Ext.create("Ext.grid.plugin.RowEditing", {                        //雙擊開始編輯                        clicksToEdit: 2                    })                ],                dockedItems: [{                    xtype: 'toolbar',                    items: [{                        text: '同步資料',                        dock: 'top',                        handler: function () {                            //同步資料方法                            store.sync();                        }                    }]                }],                columns: [{                    text: '姓名', dataIndex: 'name',                    //定義編輯狀態時的控制項,沒有定義不能編輯                    editor: {                        xtype: 'textfield',                        //是否可以為空白                        allowBlank: false                    }                }, {                    text: '年齡', dataIndex: 'age',                    editor: {                        xtype: 'datefield'                    }                }]            });

執行結果:

將第二行資料改為如下:

單擊資料同步:

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.