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实现统计复选框选中数量
Nov 24 Javascript
Jquery弹出层插件ThickBox的使用方法
Dec 09 Javascript
js鼠标点击按钮切换图片-图片自动切换-点击左右按钮切换特效代码
Sep 02 Javascript
jquery实现Slide Out Navigation滑出式菜单效果代码
Sep 07 Javascript
JavaScript程序设计高级算法之动态规划实例分析
Nov 24 Javascript
vue组件横向树实现代码
Aug 02 Javascript
详解如何配置vue-cli3.0的vue.config.js
Aug 23 Javascript
JS实现的新闻列表自动滚动效果示例
Jan 30 Javascript
Layui动态生成select下拉选择框不显示的解决方法
Sep 24 Javascript
微信小程序实现横向滚动导航栏效果
Dec 12 Javascript
原生js拖拽实现图形伸缩效果
Feb 10 Javascript
解决Vue 给mapState中定义的属性赋值报错的问题
Jun 22 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/11/01 PHP
PHP实现将几张照片拼接到一起的合成图片功能【便于整体打印输出】
2017/11/14 PHP
PHP实现的curl批量请求操作示例
2018/06/06 PHP
javascript Array.prototype.slice的使用示例
2013/11/14 Javascript
Jquery原生态实现表格header头随滚动条滚动而滚动
2014/03/18 Javascript
jQuery使用prepend()方法在元素前添加内容用法实例
2015/03/26 Javascript
js控制网页前进和后退的方法
2015/06/08 Javascript
jquery SweetAlert插件实现响应式提示框
2015/08/18 Javascript
jQuery 常用代码集锦(必看篇)
2016/05/16 Javascript
浅谈js中的三种继承方式及其优缺点
2016/08/10 Javascript
JS实现商品筛选功能
2020/08/19 Javascript
微信小程序使用toast消息对话框提示用户忘记输入用户名或密码功能【附源码下载】
2017/12/09 Javascript
详解JavaScript中操作符和表达式
2018/09/12 Javascript
解决node-sass偶尔安装失败的方法小结
2018/12/05 Javascript
webpack4手动搭建Vue开发环境实现todoList项目的方法
2019/05/16 Javascript
JavaScript enum枚举类型定义及使用方法
2020/05/15 Javascript
js实现轮播图效果 纯js实现图片自动切换
2020/08/09 Javascript
[01:59]深扒TI7聊天轮盘语音出处 1
2017/05/11 DOTA
Pycharm学习教程(7)虚拟机VM的配置教程
2017/05/04 Python
python面试题Python2.x和Python3.x的区别
2019/05/28 Python
获取Pytorch中间某一层权重或者特征的例子
2019/08/17 Python
在Python中用GDAL实现矢量对栅格的切割实例
2020/03/11 Python
Python利用matplotlib绘制散点图的新手教程
2020/11/05 Python
使用bandit对目标python代码进行安全函数扫描的案例分析
2021/01/27 Python
使用CSS3创建动态菜单效果
2015/07/10 HTML / CSS
日本著名化妆品零售网站:Cosme Land
2019/03/01 全球购物
说出一些常用的类,包,接口
2014/09/22 面试题
法学个人求职信范文
2014/01/27 职场文书
《春到梅花山》教学反思
2014/04/16 职场文书
优秀大专毕业生求职信
2014/08/04 职场文书
师德师风的心得体会
2014/09/02 职场文书
2015社区精神文明建设工作总结
2015/04/21 职场文书
2016年度基层党建工作公开承诺书
2016/03/25 职场文书
七个非常实用的Python工具包总结
2021/06/15 Python
sql字段解析器的实现示例
2021/06/23 SQL Server
vue项目中的支付功能实现(微信支付和支付宝支付)
2022/02/18 Vue.js