Gird事件机制初级读本
原文地址 文章日期: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暴露事件的列表和参数简介:
译注:下面事件解释以原文方式提供以便读者准确理解:
- 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);
- click
- dblclick
- mousedown
- mouseup
- mouseover
- mouseout
- keypress
- keydown
var img = getEl('loading-indicator'); var dm = grid.getDataModel(); dm.addListener('beforeload', img.show, img, true); dm.addListener('load', img.hide, img, true);相关文章
学习YUI.Ext 第六天--关于树TreePanel(Part 1)
这篇文章主要介绍了学习YUI.Ext 第六天--关于树TreePanel(Part 1)2007-03-03
解决extjs在firefox中关闭窗口再打开后iframe中js函数访问不到的问题
最近做ext时遇到一个问题,在firefox中浏览ext应用,加载后第一次打开一个嵌入iframe的Window时,可以直接通过js代码来执行 iframe中的js函数,但是如果将窗口关闭后重新再打开,将会抛出异常,说是funcName is not a function2008-11-11
为Yahoo! UI Extensions Grid增加内置的可编辑器
为Yahoo! UI Extensions Grid增加内置的可编辑器...2007-03-03
YUI 读码日记之 YAHOO.util.Dom - Part.1
DOM 操作是学习 Javascript 很重点的一块。YUI 提供了丰富的 DOM 操作接口,它们定义在 %BUILD%/dom/dom.js 中(封装成 YAHOO.util.Dom)。由于 DOM 操作比较重要,我计划将其分成几个 Part 分析。2008-03-03
Ext第一周 史上最强学习笔记---GridPanel(基础篇)
我不想教各位新手什么高级技术,因为我也在研究,只是想教大家一个思考的方向,能够具有举一反三的能力,能够真正学会Ext和开始深入了解。2008-12-12
学习YUI.Ext 第七天--关于View&JSONView
学习YUI.Ext 第七天--关于View&JSONView...2007-03-03


最新评论