Yes this is possible - and would be achieved in exactly the same way as you would do it with a static table (with this possible exception of using fnGetNodes() ). When you initialise the table, you can scan over it and assign the required classes, or if you are adding the data dynamically you can check the classes then, if using server-side data you could use fnDrawCallback() - there are plenty of ways to do it :-). Picking one depends on your exact scenario.
Here is my scenario.
[code]
oTable = $('#equipment').dataTable( {
"bProcessing": true,
"sAjaxSource": '/ajax.php?action=get_myequipment',
//"bLengthChange": false,
"aoColumns": [ { "bSortable": false, "bSearchable": false},null,null,null,null,null,null, { "bSortable": false }]
} )
[/code]
and the html is
[code]
+
Worn
Item
Type
Level
Quality
Bonuses
$
[/code]
I'm wanting to apply a conditional class to any row where the field Worn == 1. I've tried fnDrawCallback() but I don't think I'm fully understanding that.
Is that the best method in this case or should I try a different route?
I think the best option is probably fnInitComplete() which will fire when DataTables has loaded the data from the server and done it's initial display. At that point you can use fnGetNodes() and run through them to add the conditional classes as required.
I know the topic is quite old and I might overlooked something while searching forum. But I could not find a solution for this issue I am having (I am totally new to jQuery so please kind to me :D ):
I want to remove the odd/even format on each row (because I must have them preformatted differently). But I couldn't get it running with fnGetNodes() inside fnInitComplete()
To remove the odd/even classes that DataTables adds by default you can set asStripClasses ( http://datatables.net/usage/options#asStripClasses ) to be an empty array.
Thank you Allan, works well. :) Still I am curious, as you mentioned in your post, how you use fnGetNodes() inside fnInitComplete() since the oTable variable is not available at the time?
That's an old post (2009) and somewhat out of date now. With DataTables 1.7+ (possibly 1.6 - I can't remember just now!) the callback functions are executed with the DataTables instance's scope - so you can do this.fnGetNodes() if you want to, which is much cleaner.
Replies
Yes this is possible - and would be achieved in exactly the same way as you would do it with a static table (with this possible exception of using fnGetNodes() ). When you initialise the table, you can scan over it and assign the required classes, or if you are adding the data dynamically you can check the classes then, if using server-side data you could use fnDrawCallback() - there are plenty of ways to do it :-). Picking one depends on your exact scenario.
Regards,
Allan
Here is my scenario.
[code]
oTable = $('#equipment').dataTable( {
"bProcessing": true,
"sAjaxSource": '/ajax.php?action=get_myequipment',
//"bLengthChange": false,
"aoColumns": [ { "bSortable": false, "bSearchable": false},null,null,null,null,null,null, { "bSortable": false }]
} )
[/code]
and the html is
[code]
+
Worn
Item
Type
Level
Quality
Bonuses
$
[/code]
I'm wanting to apply a conditional class to any row where the field Worn == 1. I've tried fnDrawCallback() but I don't think I'm fully understanding that.
Is that the best method in this case or should I try a different route?
I think the best option is probably fnInitComplete() which will fire when DataTables has loaded the data from the server and done it's initial display. At that point you can use fnGetNodes() and run through them to add the conditional classes as required.
Regards,
Allan
I know the topic is quite old and I might overlooked something while searching forum. But I could not find a solution for this issue I am having (I am totally new to jQuery so please kind to me :D ):
I want to remove the odd/even format on each row (because I must have them preformatted differently). But I couldn't get it running with fnGetNodes() inside fnInitComplete()
[code]
$(document).ready(function() {
var oTable = $('#MainGrid').dataTable({
"fnInitComplete": function() {
var nNodes = oTable.fnGetNodes();
$(nNodes).each(function(){
$(this).removeClass('odd');
$(this).removeClass('even');
});
}
});
});
[/code]
if the code that remove Class stay outside the initiation, it only applies to the first page.
Again, I am sorry im new to jQuery and I know there must be a simple solution but I just could not find it
Allan
Allan