PDA

View Full Version : Adding event handleras to Grid rows.



Animal
18 Sep 2006, 4:51 AM
I need to add a dblclick handler to rows on my Grid. Double clicking on a row will switch to another tab in which the contents of the row are edited in a form.

How can I add a dblclick handler?

jack.slocum
18 Sep 2006, 12:36 PM
There is no standard way in the current version. In the new release coming shortly, the grid has a much improved event system. Direct access to the YAHOO.util.CustomEvent object has been deprecated (although will still work for now) and the new way is using a more standard addListener:

yourGrid.addListener('rowdblclick', yourHandler);

Your handler might look like this:


// grid passed for convenience to handlers
function yourHandler(grid, rowIndex){
var id = grid.getDataModel().getRowId(rowIndex);
launchTab(id);
}

The new events exposed by the grid object directly:

// raw events
'click'
'dblclick'
'mousedown'
'mouseup'
'mouseover'
'mouseout'
'keypress'
'keydown'

// calculated events
'cellclick'
'celldblclick'
'rowclick'
'rowdblclick'
'headerclick'
'rowcontextmenu'
'headercontextmenu'
'beforeedit'
'afteredit',
'bodyscroll'

Raw events give access to the raw browser event for the entire grid, calculated events are for items within the grid.

Anyway, you could do it with version .31 but it would take a little more code:


var ct = getEl('your-grid-container');
// use 'mon' instead of 'on' to get a managed (normalized) event object
ct.mon('dblclick', yourHandler);

// assumes grid object is global
function yourHandler(e){
var row = yourGrid.getRowFromChild(e.getTarget());
if(row) { // need this check in case they double clicked header instead of row
var id = yourGrid.getDataModel().getRowId(row.rowIndex);
launchTab(id);
}
}


So it's possible now, but in the next release it will much easier.

Jack

Animal
18 Sep 2006, 11:24 PM
The next realease sounds superb. Once again, I'm impressed by your innovation and work rate. Any idea when the next release will be available?

If it's soon, I'll probably wait, and just hang a listener on the rowdblclick event.

jack.slocum
19 Sep 2006, 11:02 AM
Thanks. My personal deadline for the next release is next Monday (Sept 25th). Whether I hit that is mostly dependent on whether or not I can get the documentation done. There's a ton of new stuff and I want make sure I document everything so people will actually use it.