fnGetNodes not working properly.
fnGetNodes not working properly.
I modified the example dataTables-1.7/examples/api/select_row.html with the following script. It seams that the oTable.fnGetNodes(0) is returning wrong row instead of returning first fow. Is is I am doing some thing obviously wrong.
var activerow = -1;
var act;
$(document).ready(function() {
/* Init the table */
var oTable = $('#example').dataTable( {
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
$(nRow).click( function () {
if(activerow >= 0) {
alert($(act).html());
alert(activerow);
alert($(oTable.fnGetNodes(0)).html());
$(act).removeClass('row_selected');
}
$(this).addClass('row_selected');
act = this;
activerow = iDisplayIndex;
} );
return nRow;
}
});
} );
var activerow = -1;
var act;
$(document).ready(function() {
/* Init the table */
var oTable = $('#example').dataTable( {
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
$(nRow).click( function () {
if(activerow >= 0) {
alert($(act).html());
alert(activerow);
alert($(oTable.fnGetNodes(0)).html());
$(act).removeClass('row_selected');
}
$(this).addClass('row_selected');
act = this;
activerow = iDisplayIndex;
} );
return nRow;
}
});
} );
This discussion has been closed.
Replies
The plug-in fnGetDisplayNodes ( http://datatables.net/plug-ins/api#fnGetDisplayNodes ) will get the node based on the visible index for you.
Regards,
Allan
1) When we call fnUpdate and pass activerow in second parameter is that visible index or cached index.
2) Is there anyway to get cached index in the fnRowCallback. As I understand iDisplayIndex is the display index.
Thanks.
2. If you are using fnUpdate inside fnRowCallback, you can take advantage of the fact that you can pass the TR node as the second parameter to fnUpdate (rather than an integer). Something like:
[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
this.fnUpdate( [...], nRow );
}
[/code]
Note that this is using syntax for DataTables 1.7 which is currently in beta. The only difference is the use of 'this'. 1.7 makes it much easier to use API functions inside the callbacks, by changing the execution scope. However the same principle of using nRow applies in 1.6.
Allan