Can delegate work instead of click for detail row?
Can delegate work instead of click for detail row?
Hi all,
I'm using this plugin with a table that can exceed 700 rows. Each row has a detailed row that is shown/hidden using the following code taken from the samples area:
[code]
$('td img', oTable.fnGetNodes()).each( function () {
$(this).click( function (event) {
var nTr = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "./Images/details_open.png";
oTable.fnClose( nTr );
}
else
{
/* Open this row */
this.src = "./Images/details_close.png";
oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
}
} );
} );
[/code]
This code works fine, except that I think that it could be made faster by using a delegate rather than hooking up individual click events to each and every row. I'm thinking that a delegate attached to the TBODY and targeting the TR should do. Being the jQuery noob that I am, I was wondering if:
1) I am correct ? and more importantly,
2) can anyone change the code to implement it ?
All feedback is greatly appreciated.
I'm using this plugin with a table that can exceed 700 rows. Each row has a detailed row that is shown/hidden using the following code taken from the samples area:
[code]
$('td img', oTable.fnGetNodes()).each( function () {
$(this).click( function (event) {
var nTr = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "./Images/details_open.png";
oTable.fnClose( nTr );
}
else
{
/* Open this row */
this.src = "./Images/details_close.png";
oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
}
} );
} );
[/code]
This code works fine, except that I think that it could be made faster by using a delegate rather than hooking up individual click events to each and every row. I'm thinking that a delegate attached to the TBODY and targeting the TR should do. Being the jQuery noob that I am, I was wondering if:
1) I am correct ? and more importantly,
2) can anyone change the code to implement it ?
All feedback is greatly appreciated.
This discussion has been closed.
Replies