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 相关文章推荐
js技巧--转义符"\"的妙用
Jan 09 Javascript
Discuz! 6.1_jQuery兼容问题
Sep 23 Javascript
js字符编码函数区别分析
Dec 28 Javascript
js日期时间补零的小例子
Mar 05 Javascript
url参数中有+、空格、=、%、&、#等特殊符号的问题解决
May 15 Javascript
jQuery对Select的操作大集合(收藏)
Dec 28 Javascript
moment.js轻松实现获取当前日期是当年的第几周
Feb 05 Javascript
js实现带关闭按钮始终显示在网页最底部工具条的方法
Mar 02 Javascript
JavaScript实现九九乘法表的简单实例
Jun 07 Javascript
jquery实现图片上传前本地预览
Apr 28 jQuery
View.post() 不靠谱的地方你知道多少
Aug 29 Javascript
vue2.0 路由模式mode="history"的作用
Oct 18 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
Symfony生成二维码的方法
2016/02/04 PHP
php添加数据到xml文件的简单例子
2016/09/08 PHP
解决PHP上传非标准格式的图片pjpeg失败的方法
2017/03/12 PHP
List the Codec Files on a Computer
2007/06/11 Javascript
jQuery Select(单选) 模拟插件 V1.3.62 改进版
2010/07/17 Javascript
jQuery处理xml格式的返回数据(实例解析)
2013/11/28 Javascript
基于Node.js的JavaScript项目构建工具gulp的使用教程
2016/05/20 Javascript
localStorage实现便签小程序
2016/11/28 Javascript
jQuery插件HighCharts绘制简单2D折线图效果示例【附demo源码】
2017/03/21 jQuery
如何编写jquery插件
2017/03/29 jQuery
three.js加载obj模型的实例代码
2017/11/10 Javascript
Vue shopCart 组件开发详解
2018/01/26 Javascript
layui实现动态和静态分页
2018/04/28 Javascript
angular 内存溢出的问题解决
2018/07/12 Javascript
快速解决select2在bootstrap模态框中下拉框隐藏的问题
2018/08/10 Javascript
layer弹窗在键盘按回车将反复刷新的实现方法
2019/09/25 Javascript
微信小程序页面间传递数组对象方法解析
2019/11/06 Javascript
基于JS实现视频上传显示进度条
2020/05/12 Javascript
Python对象的深拷贝和浅拷贝详解
2014/08/25 Python
详解Golang 与python中的字符串反转
2017/07/21 Python
详解Python 解压缩文件
2019/04/09 Python
python实现最短路径的实例方法
2020/07/19 Python
python实现自动打卡的示例代码
2020/10/10 Python
使用CSS3中的calc()属性来以算式表达尺寸数值
2016/06/06 HTML / CSS
VELTRA台湾:世界自由行专家
2017/08/15 全球购物
c/c++某大公司的两道笔试题
2014/02/02 面试题
毕业生自荐信
2013/12/14 职场文书
项目投资意向书
2014/04/01 职场文书
商场开业庆典策划方案
2014/06/02 职场文书
幼儿园家长安全责任书
2014/07/22 职场文书
优秀工作者事迹材料
2014/12/26 职场文书
小学少先队辅导员述职报告
2015/01/10 职场文书
长城导游词
2015/01/30 职场文书
.Net Core导入千万级数据至Mysql的步骤
2021/05/24 MySQL
总结高并发下Nginx性能如何优化
2021/11/01 Servers
SQL Server数据库查询出现阻塞之性能调优
2022/04/10 SQL Server