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 相关文章推荐
Mootools 1.2教程 Fx.Tween的使用
Sep 15 Javascript
js 判断脚本加载完毕的代码
Jul 13 Javascript
javascript string字符串优化问题
Jul 31 Javascript
JavaScript自定义DateDiff函数(兼容所有浏览器)
Mar 01 Javascript
JS实现图片预加载无需等待
Dec 21 Javascript
使用HTML+CSS+JS制作简单的网页菜单界面
Jul 27 Javascript
JavaScript调用客户端Java程序的方法
Jul 27 Javascript
jQuery基本选择器(实例及表单域value的获取方法)
May 20 Javascript
jQuery height()、innerHeight()、outerHeight()函数的区别详解
May 23 Javascript
Vue动态组件和异步组件原理详解
May 06 Javascript
详解webpack引用jquery(第三方模块)的三种办法
Aug 21 jQuery
解决vant中 tab栏遇到的坑 van-tabs
Nov 04 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
Windows 下的 PHP-PEAR 安装方法
2010/11/20 PHP
理解和运用PHP中的多态性[译]
2011/08/02 PHP
php输出金字塔的2种实现方法
2014/12/16 PHP
解决php 处理 form 表单提交多个 name 属性值相同的 input 标签问题
2017/05/11 PHP
php实现微信模拟登陆、获取用户列表及群发消息功能示例
2017/06/28 PHP
javascript动态加载三
2012/08/22 Javascript
js原生appendChild的bug解决心得分享
2013/07/01 Javascript
js中方法重载如何实现?以及函数的参数问题
2013/08/01 Javascript
node+express+ejs制作简单页面上手指南
2014/11/26 Javascript
2014 年最热门的21款JavaScript框架推荐
2014/12/25 Javascript
浅析javascript中的DOM
2015/03/01 Javascript
跟我学习javascript的严格模式
2015/11/16 Javascript
使用Promise链式调用解决多个异步回调的问题
2017/01/15 Javascript
利用JS对iframe父子(内外)页面进行操作的方法教程
2017/06/15 Javascript
vue单页应用加百度统计代码(亲测有效)
2018/01/31 Javascript
vue 子组件向父组件传值方法
2018/02/26 Javascript
解决vue页面DOM操作不生效的问题
2018/03/17 Javascript
PostgreSQL Node.js实现函数计算方法示例
2019/02/12 Javascript
基于node简单实现RSA加解密的方法步骤
2019/03/21 Javascript
vue生命周期的探索
2019/04/03 Javascript
python实现的一只从百度开始不断搜索的小爬虫
2013/08/13 Python
python提示No module named images的解决方法
2014/09/29 Python
python中Matplotlib实现绘制3D图的示例代码
2017/09/04 Python
pytorch模型预测结果与ndarray互转方式
2020/01/15 Python
Python 代码调试技巧示例代码
2020/08/11 Python
方法名是否可以与构造器的名字相同
2012/06/04 面试题
大学生表扬信范文
2014/01/09 职场文书
小区停车场管理制度
2014/01/27 职场文书
2014年两会学习心得体会
2014/03/17 职场文书
《云房子》教学反思
2014/04/20 职场文书
供应商食品安全承诺书
2015/04/29 职场文书
教师节班会开场白
2015/06/01 职场文书
银行文明优质服务培训心得体会
2016/01/09 职场文书
会议开幕致辞怎么写
2016/03/03 职场文书
python process模块的使用简介
2021/05/14 Python
Python中生成随机数据安全性、多功能性、用途和速度方面进行比较
2022/04/14 Python