extjs grid 複製問題還有一種解決方式.

來源:互聯網
上載者:User

標籤: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 複製問題還有一種解決方式.

聯繫我們

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