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中获取Radio元素值的方法
Jul 02 Javascript
jquery实现pager控件示例
Apr 09 Javascript
使用原生js写的一个简单slider
Apr 29 Javascript
jQuery队列操作方法实例
Jun 11 Javascript
JavaScript实现找出字符串中第一个不重复的字符
Sep 03 Javascript
21个JavaScript事件(Events)属性汇总
Dec 02 Javascript
举例详解Python中smtplib模块处理电子邮件的使用
Jun 24 Javascript
javascript实现跨域的方法汇总
Jun 25 Javascript
input点击后placeholder中的提示消息消失
Jan 15 Javascript
AngularJS实现动态编译添加到dom中的方法
Nov 04 Javascript
JS 实现随机验证码功能
Feb 15 Javascript
详解小程序如何动态绑定点击的执行方法
Nov 26 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
亚洲咖啡有什么?亚洲咖啡产地介绍 亚洲咖啡有什么特点?
2021/03/05 新手入门
php中CI操作多个数据库的代码
2012/07/05 PHP
php-cli简介(不会Shell语言一样用Shell)
2013/06/03 PHP
解析PHP多种序列化与反序列化的方法
2013/06/06 PHP
解析isset与is_null的区别
2013/08/09 PHP
PHP解析RSS的方法
2015/03/05 PHP
php生成过去100年下拉列表的方法
2015/07/20 PHP
PHP实现清除MySQL死连接的方法
2016/07/23 PHP
Laravel5.1自定义500错误页面示例
2016/10/09 PHP
浅谈PHP的数据库接口和技术
2016/12/09 PHP
这段js代码得节约你多少时间
2011/12/20 Javascript
Javascript简单改变表单元素背景的方法
2015/07/15 Javascript
微信小程序 详解页面跳转与返回并回传数据
2017/02/13 Javascript
jQuery插件HighCharts绘制2D柱状图、折线图的组合双轴图效果示例【附demo源码下载】
2017/03/09 Javascript
vue父组件向子组件(props)传递数据的方法
2018/01/02 Javascript
.vue文件 加scoped 样式不起作用的解决方法
2018/05/28 Javascript
一文搞懂ES6中的Map和Set
2019/05/20 Javascript
layui使用button按钮 点击出现弹层 弹层中加载表单的实例
2019/09/04 Javascript
es6中使用map简化复杂条件判断操作实例详解
2020/02/19 Javascript
解决VUE自定义拖拽指令时 onmouseup 与 click事件冲突问题
2020/07/24 Javascript
vue 动态设置img的src地址无效,npm run build 后找不到文件的解决
2020/07/26 Javascript
Vue中登录验证成功后保存token,并每次请求携带并验证token操作
2020/09/08 Javascript
[49:05]OG vs Newbee 2019DOTA2国际邀请赛淘汰赛 胜者组 BO3 第二场 8.21.mp4
2020/07/19 DOTA
Python 画出来六维图
2019/07/26 Python
TensorFlow车牌识别完整版代码(含车牌数据集)
2019/08/05 Python
opencv3/python 鼠标响应操作详解
2019/12/11 Python
python框架flask入门之环境搭建及开启调试
2020/06/07 Python
python+selenium自动化实战携带cookies模拟登陆微博
2021/01/19 Python
详解CSS3选择器的使用方法汇总
2015/11/24 HTML / CSS
详解使用双缓存解决Canvas clearRect引起的闪屏问题
2019/04/29 HTML / CSS
社区学习十八大感想
2014/01/22 职场文书
建筑工地大门标语
2014/06/18 职场文书
领导班子四风问题个人对照检查材料
2014/10/04 职场文书
党员四风问题个人对照检查材料
2014/10/26 职场文书
技术员个人工作总结
2015/03/03 职场文书
2015年初中教师个人工作总结
2015/07/21 职场文书