Gird事件机制初级读本


Posted in Javascript onMarch 10, 2007

原文地址 文章日期:2006/09/25/

 新版.32 的YUI-EXT包含了GIRD事件机制的重要升级。许多新事件现在可以用了,监听事件的机制也改变了(尽管它仍然向后兼容)。

侦听事件的方法

鉴于 YAHOO.util.CustomEvent只提供简单的访问,Grid和相关的对象扩展了新的方法来侦听事件,这些事件你应该是熟悉的。它们是:

  • addListener(eventName, fn, scope, override) - "eventName" should be one of the events defined below. "fn" is the function to call when the event occurs. "scope" is an optional object providing the scope (this) of the function. "override" is whether or not to apply that scope and is only there for backwards compatibility.
  • removeListener(eventName, fn, scope) -移除前先提交的事件侦听
  • on(eventName, fn, scope, override) - addListener 快捷方式

这些方法与YAHOO.uitl.Event一样,有相同的署名(signatures)。

onRowSelect事件的侦听:

var sm = grid.getSelectionModel(); 
sm.addListener('rowselect', myHandler);

这是GIRD暴露事件的列表和参数简介:

- "this" 指的是Grid对象;
- "e" 指的是 YAHOO.ext.EventObject (常规化事件对象) ,除了Drag & Drop对象是标准浏览器事件对象。
- "dd" 指的是Grid的YAHOO.ext.GridDD对象。

译注:下面事件解释以原文方式提供以便读者准确理解:

  • cellclick - (this, rowIndex, columnIndex, e) - Fires when a cell is clicked
  • celldblclick - (this, rowIndex, columnIndex, e) - Fires when a cell is double clicked
  • rowclick - (this, rowIndex, e) - Fires when a row is clicked
  • rowdblclick - (this, rowIndex, e) - Fires when a row is double clicked
  • headerclick - (this, columnIndex, e) - Fires when a header is clicked
  • rowcontextmenu - (this, rowIndex, e) - Fires when a row is right clicked
  • headercontextmenu - (this, columnIndex, e) - Fires when a header is right clicked
  • beforeedit - (this, rowIndex, columnIndex, e) - Fires just before editing is started on a cell
  • afteredit - (this, rowIndex, columnIndex, e) - Fires immediately after a cell is edited
  • bodyscroll - (scrollLeft, scrollTop) - Fires when the grid's body is scrolled
  • columnresize - (columnIndex, newSize) Fires when the user resizes a column.
  • startdrag - (this, dd, e) - Fires when row(s) start being dragged
  • enddrag - (this, dd, e) - Fires when a drag operation is complete
  • dragdrop - (this, dd, targetId, e) - Fires when dragged row(s) are dropped on a valid DD target
  • dragover - (this, dd, targetId, e) Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
  • dragenter - (this, dd, targetId, e) - Fires when the dragged row(s) first cross another DD target while being dragged
  • dragout - (this, dd, targetId, e) - Fires when the dragged row(s) leave another DD target while being dragged

Gird事件的例子

function onCellClick(grid, rowIndex, colIndex, e){  
 alert('Cell at row ' + rowIndex + ', column ' + colIndex + ' was clicked!'); 
 } 
 var grid = ... // 这里注册事件 grid.addListener('cellclick', onCellClick);

 

普通Grid事件
Since there is no way to envision everything you may want to do with the grid, I've also exposed direct access to many of the grid's raw events. All of these events pass one parameter to their handler: "e" a YAHOO.ext.EventObject.
  • click
  • dblclick
  • mousedown
  • mouseup
  • mouseover
  • mouseout
  • keypress
  • keydown
LoadableDataModel (from which XMLDataModel and JSONDataModel are derived) picked up a useful new event:
beforeload - Fires right before the model starts fetching remote data.
You could use this event combined with the load event to hide/show a loading indicator.
var img = getEl('loading-indicator'); var dm = grid.getDataModel(); dm.addListener('beforeload', img.show, img, true); dm.addListener('load', img.hide, img, true);
Hopefully this can get you started with the new event system. If you have any questions, feel free to post in the Help Forum and I will help you out.
Jack
Javascript 相关文章推荐
使用JQuery进行跨域请求
Jan 25 Javascript
JSChart轻量级图形报表工具(内置函数中文参考)
Oct 11 Javascript
jQuery EasyUI API 中文文档 - ComboGrid 组合表格
Oct 13 Javascript
js/jquery去掉空格,回车,换行示例代码
Nov 05 Javascript
js替代copy(示例代码)
Nov 27 Javascript
jQuery基础知识小结
Dec 22 Javascript
分享10个原生JavaScript技巧
Apr 20 Javascript
JavaScript实现的浮动层框架用法实例分析
Oct 10 Javascript
javascript断点调试心得分享
Apr 23 Javascript
Web纯前端“旭日图”实现元素周期表
Mar 10 Javascript
react.js CMS 删除功能的实现方法
Apr 17 Javascript
vue中对象数组去重的实现
Feb 06 Javascript
Gird组件 Part-3:范例RSSFeed Viewer
Mar 10 #Javascript
对YUI扩展的Gird组件 Part-2
Mar 10 #Javascript
对YUI扩展的Gird组件 Part-1
Mar 10 #Javascript
学习YUI.Ext第七日-View&JSONView Part Two-一个画室网站的案例
Mar 10 #Javascript
学习YUI.Ext 第六天--关于树TreePanel(Part 2异步获取节点)
Mar 10 #Javascript
学习YUI.Ext 第七天--关于View&JSONView
Mar 10 #Javascript
学习YUI.Ext 第六天--关于树TreePanel(Part 1)
Mar 10 #Javascript
You might like
php中inlcude()性能对比详解
2012/09/16 PHP
实例详解PHP中html word 互转的方法
2016/01/28 PHP
Prototype 工具函数 学习
2009/07/23 Javascript
Jsonp 跨域的原理以及Jquery的解决方案
2010/05/18 Javascript
深入理解JSON数据源格式
2014/01/10 Javascript
轻松创建nodejs服务器(6):作出响应
2014/12/18 NodeJs
微信小程序 生命周期函数详解
2017/05/24 Javascript
详解webpack3如何正确引用并使用jQuery库
2017/08/26 jQuery
layui 表格的属性的显示转换方法
2018/08/14 Javascript
Nodejs Express 通过log4js写日志到Logstash(ELK)
2018/08/30 NodeJs
微信小程序HTTP接口请求封装代码实例
2019/09/05 Javascript
vue自定义插件封装,实现简易的elementUi的Message和MessageBox的示例
2020/11/20 Vue.js
[57:29]Alliance vs KG 2019国际邀请赛小组赛 BO2 第二场 8.16
2019/08/17 DOTA
Python中使用pprint函数进行格式化输出的教程
2015/04/07 Python
python相似模块用例
2016/03/04 Python
Python的Tornado框架实现图片上传及图片大小修改功能
2016/06/30 Python
使用sklearn进行对数据标准化、归一化以及将数据还原的方法
2018/07/11 Python
Python Numpy:找到list中的np.nan值方法
2018/10/30 Python
pyqt5 tablewidget 利用线程动态刷新数据的方法
2019/06/17 Python
Python为何不能用可变对象作为默认参数的值
2019/07/01 Python
pygame实现成语填空游戏
2019/10/29 Python
python模式 工厂模式原理及实例详解
2020/02/11 Python
使用spring mvc+localResizeIMG实现HTML5端图片压缩上传的功能
2016/12/16 HTML / CSS
如何在Canvas中添加事件的方法示例
2019/05/21 HTML / CSS
Mio Skincare美国官网:身体紧致及孕期身体护理
2017/03/05 全球购物
一套C++笔试题面试题
2012/06/06 面试题
查询优化的一般准则有哪些
2015/03/08 面试题
大专毕业生自我鉴定
2013/11/21 职场文书
班组长的岗位职责
2013/12/09 职场文书
大学生学习党课思想汇报
2014/01/03 职场文书
2014年学校财务工作总结
2014/12/06 职场文书
2015年高考寄语或鼓励的话
2015/03/23 职场文书
2015年技术员工作总结
2015/04/10 职场文书
详解Laravel服务容器的优势
2021/05/29 PHP
Html5获取用户当前位置的几种方式
2022/01/18 HTML / CSS
http通过StreamingHttpResponse完成连续的数据传输长链接方式
2022/02/12 Python