Ext4.2的Ext.grid.plugin.RowExpander无法触发事件解决办法


Posted in Javascript onAugust 15, 2014

Ext4.2+ Ext.grid.plugin.RowExpander存在bug,添加的collapsebody,expandbody无法触发,查看了下 Ext.grid.plugin.RowExpander对应的源代码,没有添加collapsebody,expandbody事件,即使按照网上的方 法重写Ext.grid.plugin.RowExpander的init和toggleRow方法也无法触发 collapsebody,expandbody事件。

解决办法:给grid对象添加collapsebody,expandbody事件,然后给grid配置这2个事件,同时重写Ext.grid.plugin.RowExpander的toggleRow方法,触发grid添加的这2个事件即可。

测试源代码如下:

<!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无法触发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论坛找到的解决办法,这样也无法添加事件
//存储grid对象
this.grid=grid
  this.grid.addEvents('collapsebody', 'expandbody');//给grid对象添加事件
 },
 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触发事件,而不是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:'会议室1',recordDate:'2014-07-03'},
   {fileName:'文件2',room:'会议室2',recordDate:'2014-07-03'},
   {fileName:'文件3',room:'会议室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(){//无法触发这个是事件
    console.log('Ext.grid.plugin.RowExpander');
   }
  }
 });
  Ext.create('Ext.grid.Panel',{
  xtype: 'row-expander-grid',
  store: store,
  listeners:{
   expandbody:function(){//OK,可以触发
    console.log('fired from grid');
   }
  },
  renderTo:Ext.getBody(),
  columns: [
   {text: "文件名称", flex: 1, dataIndex: 'fileName'},
   {text: "会议室", 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>

Ext4.2的Ext.grid.plugin.RowExpander无法触发事件解决办法

Javascript 相关文章推荐
extjs 学习笔记(二) Ext.Element类
Oct 13 Javascript
jQuery UI AutoComplete 使用说明
Jun 20 Javascript
js判断为空Null与字符串为空简写方法
Feb 24 Javascript
JavaScript实现数字数组按照倒序排列的方法
Apr 06 Javascript
基于JavaScript实现树形下拉框
Aug 10 Javascript
JavaScript动态数量的文件上传控件
Nov 18 Javascript
node.js 发布订阅模式的实例
Sep 10 Javascript
vue观察模式浅析
Sep 25 Javascript
JavaScript实现shuffle数组洗牌操作示例
Jan 03 Javascript
vue动态加载SVG文件并修改节点数据的操作代码
Aug 17 Javascript
JavaScript交换变量常用4种方法解析
Sep 02 Javascript
JavaScript本地储存:localStorage、sessionStorage、cookie的使用
Oct 13 Javascript
javascript中的__defineGetter__和__defineSetter__介绍
Aug 15 #Javascript
js 判断图片是否加载完以及实现图片的预下载
Aug 14 #Javascript
js创建表单元素并使用submit进行提交
Aug 14 #Javascript
使用typeof判断function是否存在于上下文
Aug 14 #Javascript
java、javascript实现附件下载示例
Aug 14 #Javascript
js怎么判断flash swf文件是否加载完毕
Aug 14 #Javascript
Node.js入门教程:在windows和Linux上安装配置Node.js图文教程
Aug 14 #Javascript
You might like
浅析PHP水印技术
2007/02/14 PHP
php实现查询百度google收录情况(示例代码)
2013/08/02 PHP
在javascript中关于节点内容加强
2013/04/11 Javascript
javascript文件中引用依赖的js文件的方法
2014/03/17 Javascript
innerHTML动态添加html代码和脚本兼容多个浏览器
2014/10/11 Javascript
JS本地刷新返回上一页代码
2016/07/25 Javascript
几种二级联动案例(jQuery\Array\Ajax php)
2016/08/13 Javascript
Vue开发过程中遇到的疑惑知识点总结
2017/01/20 Javascript
关于前后端json数据的发送与接收详解
2017/07/30 Javascript
JS实现瀑布流布局
2017/10/21 Javascript
微信小程序checkbox组件使用详解
2018/01/31 Javascript
基于vue展开收起动画的示例代码
2018/07/05 Javascript
JavaScript创建对象方法实例小结
2018/09/03 Javascript
angularjs中判断ng-repeat是否迭代完的实例
2018/09/12 Javascript
vue2使用keep-alive缓存多层列表页的方法
2018/09/21 Javascript
vue-router 手势滑动触发返回功能
2018/09/30 Javascript
2019最新21个MySQL高频面试题介绍
2020/02/06 Javascript
JavaScript布尔运算符原理使用解析
2020/05/06 Javascript
vue单文件组件无法获取$refs的问题
2020/06/24 Javascript
详解React中共享组件逻辑的三种方式
2021/02/02 Javascript
使用Python获取CPU、内存和硬盘等windowns系统信息的2个例子
2014/04/15 Python
python基于windows平台锁定键盘输入的方法
2015/03/05 Python
Python面向对象之继承代码详解
2018/01/29 Python
python删除过期log文件操作实例解析
2018/01/31 Python
python smtplib模块自动收发邮件功能(二)
2018/05/22 Python
python tkinter窗口最大化的实现
2019/07/15 Python
python 实现return返回多个值
2019/11/19 Python
html5中的一些标签学习(心得)
2016/10/18 HTML / CSS
全球酒店预订网站:Hotels.com
2016/08/10 全球购物
酒吧创业计划书
2014/01/18 职场文书
《地震中的父与子》教学反思
2014/04/10 职场文书
总经理助理岗位职责范本
2015/03/31 职场文书
2015年社区平安建设工作总结
2015/05/13 职场文书
幼儿园六一主持词
2015/06/30 职场文书
2019垃圾分类宣传口号汇总
2019/08/16 职场文书
django项目、vue项目部署云服务器的详细过程
2022/07/23 Servers