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 相关文章推荐
javascript下string.format函数补充
Aug 24 Javascript
JavaScript打开word文档的实现代码(c#)
Apr 16 Javascript
javascript 获取图片尺寸及放大图片
Sep 04 Javascript
js Dialog 去掉右上角的X关闭功能
Apr 23 Javascript
JQUERY实现网页右下角固定位置展开关闭特效的方法
Jul 27 Javascript
JavaScript实现页面定时刷新(定时器,meta)
Oct 12 Javascript
jQuery中的deferred使用方法
Mar 27 jQuery
微信小程序模板和模块化用法实例分析
Nov 28 Javascript
JS实现倒计时图文效果
Nov 17 Javascript
jQuery实现网页拼图游戏
Apr 22 jQuery
vue路由对不同界面进行传参及跳转的总结
Apr 20 Javascript
video.js添加自定义组件的方法
Dec 09 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添加文章时生成静态HTML文章的实现代码
2013/02/17 PHP
PHP中数据库单例模式的实现代码分享
2014/08/21 PHP
php常用字符函数实例小结
2016/12/29 PHP
PHP通过文件路径获取文件名的实例代码
2018/10/14 PHP
PHP设计模式之观察者模式定义与用法分析
2019/04/04 PHP
thinkPHP框架通过Redis实现增删改查操作的方法详解
2019/05/13 PHP
javascript英文日期(有时间)选择器
2007/05/02 Javascript
javascript中关于break,continue的特殊用法与介绍
2012/05/24 Javascript
网页中表单按回车就自动提交的问题的解决方案
2014/11/03 Javascript
JavaScript中的变量定义与储存介绍
2014/12/31 Javascript
javascript实现了照片拖拽点击置顶的照片墙代码
2015/04/03 Javascript
Jquery检验手机号是否符合规则并根据手机号检测结果将提交按钮设为不同状态
2015/11/26 Javascript
基于jQuery实现表格的查看修改删除
2016/08/01 Javascript
jQuery实现ajax无刷新分页页码控件
2017/02/28 Javascript
详解vue-admin和后端(flask)分离结合的例子
2018/02/12 Javascript
element-ui多文件上传的实现示例
2019/04/10 Javascript
vue组件中节流函数的失效的原因和解决方法
2020/12/02 Vue.js
[00:55]2015国际邀请赛中国区预选赛5月23日——28日约战上海
2015/05/25 DOTA
python不带重复的全排列代码
2013/08/13 Python
浅谈Python数据类型判断及列表脚本操作
2016/11/04 Python
python3获取文件中url内容并下载代码实例
2019/12/27 Python
python实现简单学生信息管理系统
2020/04/09 Python
django使用channels实现通信的示例
2020/10/19 Python
独特的礼品和创新的科技产品:The Grommet
2018/02/24 全球购物
Cult Gaia官网:美国生活方式品牌
2019/08/16 全球购物
介绍Java的内部类
2012/10/27 面试题
培训主管岗位职责
2014/02/01 职场文书
自我评价的范文
2014/02/02 职场文书
幼儿教师师德演讲稿
2014/05/06 职场文书
低碳日宣传活动总结
2014/07/09 职场文书
中国梦演讲稿开场白
2014/08/28 职场文书
党员学习党的群众路线思想汇报(5篇)
2014/09/10 职场文书
行政主管岗位职责范本
2015/04/09 职场文书
2015年酒店销售部工作总结
2015/07/24 职场文书
Mysql中调试存储过程最简单的方法
2021/06/30 MySQL
python游戏开发之pygame实现接球小游戏
2022/04/22 Python