Gird事件機(jī)制初級讀本
原文地址 文章日期:2006/09/25/
新版.32 的YUI-EXT包含了GIRD事件機(jī)制的重要升級。許多新事件現(xiàn)在可以用了,監(jiān)聽事件的機(jī)制也改變了(盡管它仍然向后兼容)。
偵聽事件的方法
鑒于 YAHOO.util.CustomEvent只提供簡單的訪問,Grid和相關(guān)的對象擴(kuò)展了新的方法來偵聽事件,這些事件你應(yīng)該是熟悉的。它們是:
- 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暴露事件的列表和參數(shù)簡介:
譯注:下面事件解釋以原文方式提供以便讀者準(zhǔn)確理解:
- 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);
相關(guān)文章
ext checkboxgroup 回填數(shù)據(jù)解決
解決checkboxgroup回填數(shù)據(jù)問題的實(shí)現(xiàn)代碼2009-08-08Javascript YUI 讀碼日記之 YAHOO.util.Dom - Part.2 0
繼續(xù)在 YAHOO.util.Dom 中徘徊。由于 YAHOO.util.Dom 多次調(diào)用 batch 方法,所以先看看這個函數(shù)是怎么寫的。有關(guān) batch 的用法,可以參見這里,相關(guān)的代碼如下2008-03-03學(xué)習(xí)YUI.Ext 第六天--關(guān)于樹TreePanel(Part 2異步獲取節(jié)點(diǎn))
學(xué)習(xí)YUI.Ext 第六天--關(guān)于樹TreePanel(Part 2異步獲取節(jié)點(diǎn))...2007-03-03