標籤:pos 並且 width nts src home jsb font 版本號碼
之前的項目中儘管也常常使用到extjs,但也許是沒有注意到,也也許是根本就沒有須要用到這個功能.
前幾天在和客戶討論需求時,客戶說想要可以將gird表中的資料複製出來,當時沒多想,感覺這功能extjs應該是支援的,應該配置一個後幾個參數就能搞定的吧.但是回來後查extjs的api才發現好像根本就沒有這個設定的.再回憶之前的項目中,好像確實沒有做過這個功能.所以趕緊就到網上找了,也找個來一些解決方式,但感覺實現起來比較麻煩,也沒去試.
今天再想到這個問題時,突然一個想法在腦海中閃現,應該可以借用gird的單元格編輯功能來實現複製的效果吧.於是趕緊去測試下,結果還真可以,代碼例如以下:
Ext.create('Ext.data.Store', { storeId:'simpsonsStore', fields:['name', 'email', 'phone'], data:{'items':[ { 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" }, { 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" }, { 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" }, { 'name': 'Marge', "email":"[email protected]", "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'), <span style="color:#ff6666;">plugins: [ Ext.create('Ext.grid.plugin.CellEditing', { pluginId:'rowEditing', clicksToEdit: 1 }) ],</span> columns: [ { text: 'Name', dataIndex: 'name' , <span style="color:#ff6666;">editor:{ xtype: 'displayfield' }</span> }, { text: 'Email', dataIndex: 'email', flex: 1 }, { text: 'Phone', dataIndex: 'phone' } ], height: 200, width: 400, renderTo: Ext.getBody()});
效果例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc25haWxfc3Bvb3I=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="grid複製">
感覺效果還不錯吧,
總結起來,長處非常明顯就是實現簡單方便,支援各種版本號碼的extjs.而確定就是不支援行複製,並且須要為每一個column中都寫一個editor.
今天才發現,原來Extjs 本來就支援grid複製(添加viewConfig:{enableTextSelection:true}就可以),哎... 代碼例如以下:
Ext.create('Ext.data.Store', { storeId:'simpsonsStore', fields:['name', 'email', 'phone'], data:{'items':[ { 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" }, { 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" }, { 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" }, { 'name': 'Marge', "email":"[email protected]", "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'), viewConfig:{enableTextSelection:true}, columns: [ { text: 'Name', dataIndex: 'name' }, { text: 'Email', dataIndex: 'email', flex: 1 }, { text: 'Phone', dataIndex: 'phone' } ], height: 200, width: 400, renderTo: Ext.getBody()});
extjs grid 複製問題還有一種解決方式.