ExtJS4 表格的嵌套 rowExpander

來源:互聯網
上載者:User

標籤:des   blog   http   io   ar   使用   java   for   sp   

今天做一個grid,裡面的資料須要帶明細,思來想去還是搞個表格嵌套吧!看


對於grid中每一條記錄點擊左邊的+號能展開一個明細的子表格 全部資料包含列名均從後台獲得,子表格的資料臨時在本地以做測試


在此貼一些代碼留下記錄

function displayInnerGrid(renderId) {    //Model for the inside grid store    Ext.define(‘TestModel‘, {        extend: ‘Ext.data.Model‘,        fields: [            { name: ‘Field1‘ },            { name: ‘Field2‘ },            { name: ‘Field3‘ }        ]    });    //dummy data for the inside grid    var dummyDataForInsideGrid = [        [‘a‘, ‘a‘, ‘a‘],        [‘b‘, ‘b‘, ‘b‘],        [‘c‘, ‘c‘, ‘c‘]    ];    var insideGridStore = Ext.create(‘Ext.data.ArrayStore‘, {        model: ‘TestModel‘,        data: dummyDataForInsideGrid    });    innerGrid = Ext.create(‘Ext.grid.Panel‘, {        store: insideGridStore,        selModel: {            selType: ‘cellmodel‘        },        columns: [            { text: "明細1", dataIndex: ‘Field1‘ },            { text: "明細2", dataIndex: ‘Field2‘ },            { text: "明細3", dataIndex: ‘Field3‘ }        ],        columnLines: true,        autoWidth: true,        autoHeight: true,        //width: 400,        //height: 200,        frame: false,      //  iconCls: ‘icon-grid‘,        renderTo: renderId    });   /*  innerGrid.getEl().swallowEvent([                ‘mousedown‘, ‘mouseup‘, ‘click‘,                ‘contextmenu‘, ‘mouseover‘, ‘mouseout‘,                ‘dblclick‘, ‘mousemove‘            ]); */}  function destroyInnerGrid(record) {    var parent = document.getElementById(record.get(‘id‘));    var child = parent.firstChild;    while (child) {        child.parentNode.removeChild(child);        child = child.nextSibling;    }}  

grid_huizong.view.on(‘expandBody‘, function (rowNode, record, expandRow, eOpts) {//console.log(record.get(‘id‘));        displayInnerGrid(record.get(‘id‘));    });    grid_huizong.view.on(‘collapsebody‘, function (rowNode, record, expandRow, eOpts) {        destroyInnerGrid(record);    });

以上代碼為grid綁定事件。。詳細代碼啥意思應該能看懂


注意在定義grid的時候使用

plugins: [{        ptype: ‘rowexpander‘,        rowBodyTpl : [                ‘<div id="{id}">‘,                ‘</div>‘            ]}],

這個是rowexpander外掛程式。。網上有人說用的時候須要引用,可是我沒引用什麼也能夠用了?


注意上面三段代碼中關鍵的id,這個id你能夠改,可是須要改成後台發過來的資料中fields中的第一項。。我這個範例後台發過來的fields第一項是id


最後給一個我參考的連結  這裡



ExtJS4 表格的嵌套 rowExpander

聯繫我們

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