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

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>

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索ext
, grid
, plugin
, RowExpander
无法触发事件
ext.grid.rowexpander、extjs rowexpander、extjs5 rowexpander、ext rowexpander、extjs plugin,以便于您获取更多的相关知识。

时间: 2024-08-31 08:42:00

Ext4.2的Ext.grid.plugin.RowExpander无法触发事件解决办法_extjs的相关文章

Ext.grid.GridPanel单元格特殊设置

<html>     <head>         <title>03.grid</title>         <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />         <script type="text/javascript" src=&

Ext Grid控件的配置与方法

  1.Ext.grid.GridPanel 主要配置项: store:表格的数据集 columns:表格列模式的配置数组,可自动创建ColumnModel列模式 autoExpandColumn:自动充满表格未用空间的列,参数为列id,该id不能为0 stripeRows:表格是否隔行换色,默认为false cm.colModel:表格的列模式,渲染表格时必须设置该配置项 sm.selModel:表格的选择模式,默认为Ext.grid.RowSelectionModel enableHdMen

Ext.grid.CheckboxSelectionModel()-怎么实现点击一行,其他已选行不消失

问题描述 刚开始接触ext,用到Ext.grid.CheckboxSelectionModel()时,总是出现这个问题,希望大家能给解决一下.我用的是ext3.1.0  当我已经选择了四行 当我要选择第五行时,如果不点击红色圈圈范围内,或点击第五行中任意一个cell(下图圈中的位置),原来选中的四行就会消失.如下 我想达到效果就是点击这一行的哪个位置都可以选中这一行,而且原来的已选项不会消失. 在网上找了一个哥们解决的方法:定义 var sm = new Ext.grid.CheckboxSel

jquery ext grid 实现动态添加,删除一行。急!!! 大神们求帮忙!10分

问题描述 jquery ext grid 实现动态添加,删除一行.急!!! 大神们求帮忙!10分 解决方案 Ext如何动态添加一行组件EXT增加删除一行 解决方案二: 添加http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add 删除,通过find找到记录,然后调用removehttp://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-findhttp

ext grid分页出错问题

问题描述 我要做ext grid分页,按例子做一直做不出来,在firebug上显示错误如下:[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: jav

ExtJs之Ext.grid.GridPanel(部分未完)

今天在家休息,年假不用就作费啊. 看了几部香港老电影,陪爸爸看了勇士占奇才, 然后,测试了一下EXTJS未完的内容, 在京东上订了七本历史普及书,近两百块..:) 搞定. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

ext grid 数据加载成功,却显示不了数据

问题描述 我的grid从后台加载数据成功,却显示不了数据 !整体布局是一个viewport,左侧树形,右侧表格,当我单击树形的值时,在表格显示结果.===========================================这是grid 代码:CurrentDataGrid = function(viewer, config){ this.viewer = viewer; Ext.apply(this, config); this.store = new Ext.data.Store(

ext-为什么EXT grid不能显示数据?

问题描述 为什么EXT grid不能显示数据? 求解,为什么grid里面没有数据显示?各位大神帮帮忙 解决方案 你看下你的响应里面的Json数据的key值是不是dataIndex里面的值,应该是没对应上 解决方案二: 补充:整合DWR调用数据,打断点显示data能取到数据,但是为什么grid里面没有显示?

EXT Grid 相关问题,求指点,拜托

问题描述 最近项目里用Ext Grid ,现在有一段代码,其中三个参数我不清楚接收的到底是什么值,请教各位指点一下.代码如下:各位,不好意思,没有什么分,我没分了,请各位帮下忙吧,顺带熟悉熟悉或者加深印象也好对吧.谢谢Ext.onReady(function(){var path = $("input[name=path]").val();var sm = new Ext.grid.CheckboxSelectionModel({}); //问题在此处!!! javascript代码没