Ext4.2的Ext.grid.plugin.RowExpander無法觸發(fā)事件解決辦法
Ext4.2+ Ext.grid.plugin.RowExpander存在bug,添加的collapsebody,expandbody無法觸發(fā),查看了下 Ext.grid.plugin.RowExpander對(duì)應(yīng)的源代碼,沒有添加collapsebody,expandbody事件,即使按照網(wǎng)上的方 法重寫Ext.grid.plugin.RowExpander的init和toggleRow方法也無法觸發(fā) collapsebody,expandbody事件。
解決辦法:給grid對(duì)象添加collapsebody,expandbody事件,然后給grid配置這2個(gè)事件,同時(shí)重寫Ext.grid.plugin.RowExpander的toggleRow方法,觸發(fā)grid添加的這2個(gè)事件即可。
測(cè)試源代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Ext4.2+ Ext.grid.plugin.RowExpander無法觸發(fā)collapsebody,expandbody事件解決辦法</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" rel="external nofollow" />
<script type="text/javascript" src="../../ext-all-debug.js"> </script>
<script>
Ext.override(Ext.grid.plugin.RowExpander, { // Override to fire collapsebody & expandbody
init: function(grid) {
this.callParent(arguments);
// grid.getView().addEvents('collapsebody', 'expandbody');//ext論壇找到的解決辦法,這樣也無法添加事件
//存儲(chǔ)grid對(duì)象
this.grid=grid
this.grid.addEvents('collapsebody', 'expandbody');//給grid對(duì)象添加事件
},
toggleRow: function(rowIdx, record) {
var me = this,
view = me.view,
rowNode = view.getNode(rowIdx),
row = Ext.fly(rowNode, '_rowExpander'),
nextBd = row.down(me.rowBodyTrSelector, true),
isCollapsed = row.hasCls(me.rowCollapsedCls),
addOrRemoveCls = isCollapsed ? 'removeCls' : 'addCls',
ownerLock, rowHeight, fireView;
// Suspend layouts because of possible TWO views having their height change
Ext.suspendLayouts();
row[addOrRemoveCls](me.rowCollapsedCls);
Ext.fly(nextBd)[addOrRemoveCls](me.rowBodyHiddenCls);
me.recordsExpanded[record.internalId] = isCollapsed;
view.refreshSize();
// Sync the height and class of the row on the locked side
if (me.grid.ownerLockable) {
ownerLock = me.grid.ownerLockable;
// fireView = ownerLock.getView();
view = ownerLock.lockedGrid.view;
fireView=ownerLock.lockedGrid.view;
rowHeight = row.getHeight();
// EXTJSIV-9848: in Firefox the offsetHeight of a row may not match
// it is actual rendered height due to sub-pixel rounding errors. To ensure
// the rows heights on both sides of the grid are the same, we have to set
// them both.
row.setHeight(isCollapsed ? rowHeight : '');
row = Ext.fly(view.getNode(rowIdx), '_rowExpander');
row.setHeight(isCollapsed ? rowHeight : '');
row[addOrRemoveCls](me.rowCollapsedCls);
view.refreshSize();
} else {
fireView = view;
}
//通過grid觸發(fā)事件,而不是view
this.grid.fireEvent(isCollapsed ? 'expandbody' : 'collapsebody', row.dom, record, nextBd);
//下面為ext論壇的解決辦法,無效
//fireView.fireEvent(isCollapsed ? 'expandbody' : 'collapsebody', row.dom, record, nextBd);
// Coalesce laying out due to view size changes
Ext.resumeLayouts(true);
},
});
//Ext.loader.setConfig({enabled:true});
Ext.onReady(function() {
Ext.QuickTips.init();
var store = new Ext.data.Store({
fields:[
{name:'fileName',type:'string'},
{name:'room',type:'string'},
{name:'recordDate',type:'string'},
],
data:[
{fileName:'文件1',room:'會(huì)議室1',recordDate:'2014-07-03'},
{fileName:'文件2',room:'會(huì)議室2',recordDate:'2014-07-03'},
{fileName:'文件3',room:'會(huì)議室3',recordDate:'2014-07-03'}
],
autoLoad:true
});
var expander = new Ext.grid.plugin.RowExpander({
rowBodyTpl:new Ext.XTemplate('<div class="detailData">pp</div>'),
listeners:{
expandbody:function(){//無法觸發(fā)這個(gè)是事件
console.log('Ext.grid.plugin.RowExpander');
}
}
});
Ext.create('Ext.grid.Panel',{
xtype: 'row-expander-grid',
store: store,
listeners:{
expandbody:function(){//OK,可以觸發(fā)
console.log('fired from grid');
}
},
renderTo:Ext.getBody(),
columns: [
{text: "文件名稱", flex: 1, dataIndex: 'fileName'},
{text: "會(huì)議室", dataIndex: 'room'},
{text: "錄制日期", renderer: Ext.util.Format.dateRenderer('Y-m-d'), dataIndex: 'recordDate'}
],
width: 600,
height: 300,
plugins:expander,
collapsible: true,
animCollapse: false,
title: 'Expander Rows in a Collapsible Grid',
iconCls: 'icon-grid'
});
});
</script>
</head>
<body id="docbody">
</body>
</html>

相關(guān)文章
extjs grid設(shè)置某列背景顏色和字體顏色的方法
extjs grid設(shè)置某列背景顏色和字體顏色的方法,需要的朋友可以參考下。2010-09-09
Extjs TimeField 顯示正常時(shí)間格式的代碼
由后臺(tái)返回的json的日期時(shí)間格式中,往往都是 類似 "\/Date(1309200300000)\/"的日期時(shí)間格式,結(jié)果導(dǎo)致無法正常在TimeField中顯示2011-06-06
Extjs中TabPane如何嵌套在其他網(wǎng)頁中實(shí)現(xiàn)思路及代碼
Extjs中TabPane在一些特殊用途時(shí)把其嵌在其他的網(wǎng)頁中,很多新手朋友可能對(duì)此不是很熟悉,小編就在本文章中詳細(xì)的介紹一下,感興趣的你可不要錯(cuò)過了啊,希望本文對(duì)你有所幫助2013-01-01
ExtJS4 動(dòng)態(tài)生成的grid導(dǎo)出為excel示例
解決了一個(gè)表格不能重復(fù)下載的小BUG,一個(gè)使用grid初始化發(fā)生的BUG,需要的朋友可以參考下2014-05-05
extjs_02_grid顯示本地?cái)?shù)據(jù)、顯示跨域數(shù)據(jù)
這篇文章主要介紹了extjs_02_grid顯示本地?cái)?shù)據(jù)、顯示跨域數(shù)據(jù)的具體實(shí)現(xiàn),需要的朋友可以參考下2014-06-06
ExtJS 設(shè)置級(jí)聯(lián)菜單的默認(rèn)值
ExtJS在修改這樣的頁面上賦值是很方便的,在正文中1.2.1代碼中可以看出,一行代碼就可以搞定,但這是對(duì)于普通控件而言,如文本框。對(duì)于ComboBox可沒這么簡(jiǎn)單...2010-06-06
ANT 壓縮(去掉空格/注釋)JS文件可提高js運(yùn)行速度
在解決這個(gè)有很多優(yōu)化方法,今天來說其中一種,那就是在Ant腳本打包的時(shí)候,把js中空格、注釋去掉、以及合并,合并今天不說了,還未實(shí)現(xiàn)這個(gè),在研究中2013-04-04

