Assigning fnRowCallback after the dataTable() call

Assigning fnRowCallback after the dataTable() call

MithrusMithrus Posts: 19Questions: 0Answers: 0
edited February 2010 in General
I've seen many examples of having the fnRowCallback defined as part of the dataTable() call, but is it possible to add this later?

Say I have this:
[code]oTable = $("table#summary").dataTable();[/code]Is it possible to do something like
[code]oTable.fnRowCallback = function(nRow,aData,iDisplayIndex) {
keyids = new Array(0);
var id = "";
for (k in keyids) id = id.concat(aData[k],",");
if (id.charAt(id.length-1)) = ",") id = id.substring(0,id.length-1);
$(nRow).attr("id",id);
return nRow;
}[/code]This doesn't work, and I can't figure out if that's even possible. Is there a valid syntax to assign the callback function after the initialization?

Replies

  • allanallan Posts: 65,421Questions: 1Answers: 10,864 Site admin
    It's not really supported (because it wasn't designed with this in mind) but this should work:

    [code]
    var oTable = $("table#summary").dataTable();
    var oSettings = oTable.fnSettings();
    oSettings.fnRowCallback = function (...){...};
    [/code]
    It's worth noting that this uses some of DataTables internals, so it is possible that this might change in future (although unlikely in the near future - it's been there since 1.0.0!).

    Regards,
    Allan
This discussion has been closed.