How can i register multiple fnRowCallback for same DT?
How can i register multiple fnRowCallback for same DT?
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
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
This discussion has been closed.
Replies
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
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.
Allan
how about if i destroy and then redraw when i get more information?
Allan