ExtJS4 表格的嵌套 rowExpander應(yīng)用
更新時(shí)間:2014年05月02日 11:42:17 作者:
今天做一個(gè)grid,里面的數(shù)據(jù)需要帶明細(xì),思來(lái)想去還是搞個(gè)表格嵌套吧,需要的朋友可以參考下
今天做一個(gè)grid,里面的數(shù)據(jù)需要帶明細(xì),思來(lái)想去還是搞個(gè)表格嵌套吧!看下圖
對(duì)于grid中每一條記錄點(diǎn)擊左邊的+號(hào)能展開(kāi)一個(gè)明細(xì)的子表格 所有數(shù)據(jù)包括列名均從后臺(tái)獲得,子表格的數(shù)據(jù)暫時(shí)在本地以做測(cè)試
在此貼一些代碼留下記錄
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: "明細(xì)1", dataIndex: 'Field1' },
{ text: "明細(xì)2", dataIndex: 'Field2' },
{ text: "明細(xì)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綁定事件。。具體代碼啥意思應(yīng)該能看懂
注意在定義grid的時(shí)候使用
plugins: [{
ptype: 'rowexpander',
rowBodyTpl : [
'<div id="{id}">',
'</div>'
]
}],
這個(gè)是rowexpander插件。。網(wǎng)上有人說(shuō)用的時(shí)候需要引用,但是我沒(méi)引用什么也可以用了?
注意上面三段代碼中關(guān)鍵的id,這個(gè)id你可以改,但是需要改成后臺(tái)發(fā)過(guò)來(lái)的數(shù)據(jù)中fields中的第一項(xiàng)。。我這個(gè)例子后臺(tái)發(fā)過(guò)來(lái)的fields第一項(xiàng)是id

對(duì)于grid中每一條記錄點(diǎn)擊左邊的+號(hào)能展開(kāi)一個(gè)明細(xì)的子表格 所有數(shù)據(jù)包括列名均從后臺(tái)獲得,子表格的數(shù)據(jù)暫時(shí)在本地以做測(cè)試
在此貼一些代碼留下記錄
復(fù)制代碼 代碼如下:
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: "明細(xì)1", dataIndex: 'Field1' },
{ text: "明細(xì)2", dataIndex: 'Field2' },
{ text: "明細(xì)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;
}
}
復(fù)制代碼 代碼如下:
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綁定事件。。具體代碼啥意思應(yīng)該能看懂
注意在定義grid的時(shí)候使用
復(fù)制代碼 代碼如下:
plugins: [{
ptype: 'rowexpander',
rowBodyTpl : [
'<div id="{id}">',
'</div>'
]
}],
這個(gè)是rowexpander插件。。網(wǎng)上有人說(shuō)用的時(shí)候需要引用,但是我沒(méi)引用什么也可以用了?
注意上面三段代碼中關(guān)鍵的id,這個(gè)id你可以改,但是需要改成后臺(tái)發(fā)過(guò)來(lái)的數(shù)據(jù)中fields中的第一項(xiàng)。。我這個(gè)例子后臺(tái)發(fā)過(guò)來(lái)的fields第一項(xiàng)是id
您可能感興趣的文章:
- Extjs grid添加一個(gè)圖片狀態(tài)或者按鈕的方法
- ExtJS[Desktop]實(shí)現(xiàn)圖標(biāo)換行示例代碼
- 解決Extjs上傳圖片無(wú)法預(yù)覽的解決方法
- ExtJs之帶圖片的下拉列表框插件
- ExtJS 4.2 Grid組件單元格合并的方法
- ExtJS4的文本框(textField)使用正則表達(dá)式進(jìn)行驗(yàn)證(Regex)的方法
- ExtJS4給Combobox設(shè)置列表中的默認(rèn)值示例
- ExtJS4如何自動(dòng)生成控制grid的列顯示、隱藏的checkbox
- extJS中常用的4種Ajax異步提交方式
- extjs4 treepanel動(dòng)態(tài)改變行高度示例
- ExtJS4中的requires使用方法示例介紹
- extjs4圖表繪制之折線圖實(shí)現(xiàn)方法分析
相關(guān)文章
EXTJS記事本 當(dāng)CompositeField遇上RowEditor
用RowEditor作批量編輯器時(shí),遇到一個(gè)問(wèn)題,想要在Roweditor中使用三個(gè)下拉列表組成級(jí)聯(lián)式選擇控件2011-07-07Extjs中ComboBoxTree實(shí)現(xiàn)的下拉框樹(shù)效果(自寫)
最近涉及到的一個(gè)項(xiàng)目中,需要實(shí)現(xiàn)ComboBoxTree的效果,由于在Extjs中是沒(méi)有這種效果,所以看看別人的資料自己寫了一個(gè),感興趣的朋友可以參考下哈2013-05-05Ext修改GridPanel數(shù)據(jù)和字體顏色、css屬性等
這篇文章主要介紹了Ext修改GridPanel數(shù)據(jù)和字體顏色、css屬性等,需要的朋友可以參考下2014-06-06Ext中下拉列表ComboBox組件store數(shù)據(jù)格式用法介紹
本文為大家詳細(xì)介紹下Ext中下拉列表ComboBox組件store數(shù)據(jù)格式的基本用法,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-07-07extjs 3.31 TreeGrid實(shí)現(xiàn)靜態(tài)頁(yè)面加載json到TreeGrid里面
extjs 3.31 TreeGrid 我的小改動(dòng),實(shí)現(xiàn)靜態(tài)頁(yè)面加載json到TreeGrid里面2013-04-04學(xué)習(xí)ExtJS fit布局使用說(shuō)明
ExtJS fit布局使用說(shuō)明,需要的朋友可以參考下。2009-10-10