extjs grid 複製問題另一種解決方案.

來源:互聯網
上載者:User

extjs grid 複製問題另一種解決方案.

之前的項目中雖然也經常使用到extjs,但或許是沒有注意到,也或許是根本就沒有需要用到這個功能.

前幾天在和客戶討論需求時,客戶說想要能夠將gird表中的資料複製出來,當時沒多想,感覺這功能extjs應該是支援的,應該配置一個後幾個參數就能搞定的吧.可是回來後查extjs的api才發現好像根本就沒有這個設定的.再回想之前的項目中,好像確實沒有做過這個功能.所以趕緊就到網上找了,也找個來一些解決方案,但感覺實現起來比較麻煩,也沒去試.

今天再想到這個問題時,突然一個想法在腦海中閃現,應該能夠借用gird的單元格編輯功能來實現複製的效果吧.於是趕緊去測試下,結果還真可以,代碼如下:

Ext.create('Ext.data.Store', {    storeId:'simpsonsStore',    fields:['name', 'email', 'phone'],    data:{'items':[        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }    ]},    proxy: {        type: 'memory',        reader: {            type: 'json',            root: 'items'        }    }});Ext.create('Ext.grid.Panel', {    title: 'Simpsons',    store: Ext.data.StoreManager.lookup('simpsonsStore'),    plugins: [        Ext.create('Ext.grid.plugin.CellEditing', {            pluginId:'rowEditing',            clicksToEdit: 1        })    ],    columns: [        { text: 'Name',  dataIndex: 'name' ,         editor:{             xtype: 'displayfield'         }        },        { text: 'Email', dataIndex: 'email', flex: 1 },        { text: 'Phone', dataIndex: 'phone' }    ],    height: 200,    width: 400,    renderTo: Ext.getBody()});

效果如下:


感覺效果還不錯吧,

總結起來,優點很明顯就是實現簡單方便,支援各種版本的extjs.而確定就是不支援行複製,而且需要為每個column中都寫一個editor.

聯繫我們

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