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(1.3.2) 7行代码搞定跟随屏幕滚动的层
May 21 Javascript
在javascript中执行任意html代码的方法示例解读
Dec 25 Javascript
javascript字母大小写转换的4个函数详解
May 09 Javascript
探讨JavaScript中的Rest参数和参数默认值
Jul 29 Javascript
javascript中字体浮动效果的简单实例演示
Nov 18 Javascript
Jquery Easyui分割按钮组件SplitButton使用详解(17)
Dec 18 Javascript
Vue 父子组件、组件间通信
Mar 08 Javascript
Node.js使用Angular简单示例
May 11 Javascript
vue+axios新手实践实现登陆的示例代码
Jun 06 Javascript
react高阶组件添加和删除props
Apr 26 Javascript
Vue结合路由配置递归实现菜单栏功能
Jun 16 Javascript
微信小程序input抖动问题的修复方法
Mar 03 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笔记之:文章中图片处理的使用
2013/04/26 PHP
深入php self与$this的详解
2013/06/08 PHP
thinkphp中连接oracle时封装方法无法用的解决办法
2013/06/17 PHP
列表内容的选择
2006/06/30 Javascript
FCK调用方法..
2006/12/21 Javascript
js Html结构转字符串形式显示代码
2011/11/15 Javascript
《JavaScript高级程序设计》阅读笔记(三) ECMAScript中的引用类型
2012/02/27 Javascript
解决IE6的PNG透明JS插件使用介绍
2013/04/17 Javascript
使用Plupload实现直接上传附件至七牛云存储
2014/12/26 Javascript
基于jQuery实现的旋转彩圈实例
2015/06/26 Javascript
javascript模拟C#格式化字符串
2015/08/26 Javascript
javascript  删除select中的所有option的实例
2017/09/17 Javascript
AngularJs ng-change事件/指令的用法小结
2017/11/01 Javascript
最新Javascript程序员面试试题和解题方法
2017/11/23 Javascript
vue配置多页面的实现方法
2018/05/22 Javascript
vue超时计算的组件实例代码
2018/07/09 Javascript
用图片替换checkbox原始样式并实现同样的功能
2018/11/15 Javascript
Vue.js中 v-model 指令的修饰符详解
2018/12/03 Javascript
谈谈JavaScript中super(props)的重要性
2019/02/12 Javascript
jQuery选择器之基本过滤选择器用法实例分析
2019/02/19 jQuery
教你使用vue-cli快速构建的小说阅读器
2019/05/13 Javascript
ZK中使用JS读取客户端txt文件内容问题
2019/11/07 Javascript
python调用c++传递数组的实例
2019/02/13 Python
Python实现去除图片中指定颜色的像素功能示例
2019/04/13 Python
Python 类属性与实例属性,类对象与实例对象用法分析
2019/09/20 Python
python cv2.resize函数high和width注意事项说明
2020/07/05 Python
python中的django是做什么的
2020/07/31 Python
市场专员岗位职责
2014/02/14 职场文书
2014年五一活动策划方案
2014/03/15 职场文书
公司委托书格式范文
2014/10/09 职场文书
2015质检员个人年终工作总结
2015/10/23 职场文书
python3美化表格数据输出结果的实现代码
2021/04/14 Python
使用numpy nonzero 找出非0元素
2021/05/14 Python
Python中glob库实现文件名的匹配
2021/06/18 Python
HTML中的表格元素介绍
2022/02/28 HTML / CSS
Python实现猜拳与猜数字游戏的方法详解
2022/04/06 Python