Event subscription after initialization
Event subscription after initialization
I need to subscribe to the fnRowCallback of a table that has already been initialized. I've tried doing this by setting "bRetrieve": true in the orignal table initialization, but when I then try to create a fnRowCallback event by
[code]
$("#MyTable").dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
console.log("Row Callback");
return nRow
}
});
[/code]
everything is reset in the datatable, but the row callback does work. Any help is much appreciated!
Thanks
[code]
$("#MyTable").dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
console.log("Row Callback");
return nRow
}
});
[/code]
everything is reset in the datatable, but the row callback does work. Any help is much appreciated!
Thanks
This discussion has been closed.
Replies
[code]
$("#MyTable").dataTable().fnSettings().fnRowCallback =
function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
console.log("Row Callback");
return nRow
}
[/code]
and it still seems to reset the datatable.
Allan
[code]
$("#MyTable").dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull) {return myRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull);}
});
myRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
return nRow;
}
[/code]
Then outside of the class that handles the above initialization, we can override the row callback by:
[code]
myRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
console.log("New fnRowCallback");
return nRow;
}
[/code]
This seems to work well. Is there anything I may be doing wrong in my first two posts that would let me not have to write the code in this way?
Thanks.
[code]
$(document).ready(function() {
$('#example').dataTable();
$("#example").dataTable().fnSettings().fnRowCallback =
function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
console.log("Row Callback");
return nRow
}
} );
[/code]
It works as I would expect - on the first draw (i.e. the initialisation) it will not show any log message. Then when you do the next draw (i.e. change page or sort etc) you get a log message for each log shown. Is that basically what you are looking for?
Allan
This code seems to work fine unless you define other attributes in the table's initialization. That is
[code]
$('#MyTable').dataTable({
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": true,
"bFilter": false,
"bSort": false,
"bInfo": false,
"bAutoWidth": true,
"aoColumns": [
{"bVisible": 0 },
{"bVisible": 0 },
null,
null,
null,
null,
{"bVisible": 0 },
null,
{"bVisible": 0 },
null,
null,
null,
null,
null,
{"bVisible": 0 },
null,
null,
null
]
});
[/code]
and then executing
[code]
$("#MyTable").dataTable().fnSettings().fnRowCallback =
function( nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
console.log("Row Callback");
return nRow
}
[/code]
makes, in particular, bJQueryUI no longer work. I have not checked what other attributes are lost. As I said before, I have circumvented the problem by initializing the table with a stubbed in row callback function that can then later be overwritten. Let me know if you need any other feedback or have any ideas about why the table behaves this way.
Thanks again