How can i register multiple fnRowCallback for same DT?

How can i register multiple fnRowCallback for same DT?

netametanetameta Posts: 39Questions: 0Answers: 0
edited December 2013 in General
So i am trying to have several formatting done on a table like: i have duration column in secs and i format it to string - i am doing that server side. the issue is when i try sorting. since its a string the whole thing is a mass.

For example 3850 secs turns into "about 1 hour, 4 minutes". so sorting wise this wont work correctly.

what i had in mind is when i create the table(sever side) to not do the formatting yet, then either on fnDrawCallback or fnRowCallback to do the formatting. so basically the sorting will be numeric not string.

If this is the preferred way then how do i register multiple fnRowCallback Or drawCallback as i might need to do it on several columns at different times(not on initiation).

Here is what i tried so far.

[code]
var table = $('#selector').dataTable();
table.fnSettings().aoRowCallback.push(
{ "sName" : "fName", "fn" : function(nRow, aData, iDisplayIndex, iDisplayIndexFull){
console.log(nRow, aData, iDisplayIndex, iDisplayIndexFull);
}
}

//when i run this it wouldn't console.log and wont run this function. in aoRowCallback it does add the function.

//now since i cannot do

var table = $('#selector').dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
alert('someSome');
}
});

table.dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
alert('someSome');
}
});

again because you cant inititate it again. i dont know how to register multiple fnRowCallback .

[/code]

Thanks in advanced

Replies

  • allanallan Posts: 65,411Questions: 1Answers: 10,860 Site admin
    I would suggest you do your string formatting in mRender and not fnRowCallback as it is much more efficient.

    However, currently it is not possible to attach multiple functions to fnRowCallback . If that is what you want, you would need to have your fnRowCallback call the multiple functions. Perhaps you could use an event / subscribe system if you really wanted.

    Allan
  • netametanetameta Posts: 39Questions: 0Answers: 0
    edited December 2013
    Allan. Thanks for your help.

    I like the new design alot btw.

    Did not work with mRender yet but will see how that goes.

    However aoRowCallback is an array i was sure it would run all the functions inside it.
  • allanallan Posts: 65,411Questions: 1Answers: 10,860 Site admin
    Yes, aoRowCallback is an array, but its an internal array. The public API only presents fnRowCallback which is a single function which is added to aoRowCallback . There is no method to add multiple entities to aoRowCallback using the public API.

    Allan
  • netametanetameta Posts: 39Questions: 0Answers: 0
    mRender is awesome. probably exactly what i am looking for apart for the fact : when i initialize the table i dont have all the column needed. so i guess that's ruled out as well.

    how about if i destroy and then redraw when i get more information?
  • allanallan Posts: 65,411Questions: 1Answers: 10,860 Site admin
    if you remove a row, then the data just disappears. If you have assigned static events, remember to unbind the events so you don't get memory leaks.

    Allan
This discussion has been closed.