change class of paginated rows
change class of paginated rows
Hi!
I am trying to reformat rows of a datatable.
The data of the table is more or less a listing of folders.
All I want to do is remove class from each and add a new one.
[code]
$(function(){
$("tr[id^='folder']").each(function(){
$(this).removeClass('gradeA').addClass('gradeU');
}
);
});
[/code]
This works fine as long as the table is not paginated and not filtered.
Thanks
Mat
I am trying to reformat rows of a datatable.
The data of the table is more or less a listing of folders.
All I want to do is remove class from each and add a new one.
[code]
$(function(){
$("tr[id^='folder']").each(function(){
$(this).removeClass('gradeA').addClass('gradeU');
}
);
});
[/code]
This works fine as long as the table is not paginated and not filtered.
Thanks
Mat
This discussion has been closed.
Replies
You have fndrawCallback event which triggers on every redraw of table, so you could do this:
[code]
oTable= $('#table').dataTable({
"sAjaxSource": "YourSource",
...
"fnDrawCallback": function () { //your function here },
...
});
[/code]
Allan
It works finally (though I do not fully understand why and how):
First:
Initialize document and datatable:
[code]
$(document).ready(function() {
oTable = $('#table-result').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"fnDrawCallback": function(){
$("tr[id^='folder']").each(function(){
$(this).removeClass('gradeA').addClass('gradeU');
});
$("#folder_"+ current_folder_ind).removeClass('gradeU').addClass('gradeA');
}
});
});
[/code]
The second function reformats the rows, which are just visible (old behaviour) without redrawing the table.
This function is called when a button within the table is pressed.
@allen: That's why I cannot do all css at the beginning.
[code]
$(function(){
$("tr[id^='folder']").each(function(){
$(this).removeClass('gradeA').addClass('gradeU');
}
);
$("#folder_"+ folder_ind).removeClass('gradeU').addClass('gradeA');
});
[/code]
I could get rid of that function, if I could force the datatable to redraw.
http://datatables.net/api#fnDraw :-)
Allan
this simple line just eliminated a whole block of code:
[code]
oTable.fnDraw(false);
[/code]
So cool, so great.
I added a button on top of the page (outside the datatable).
[code]
$( "#button").button();
[/code]
After redrawing the table, it seems that the button looses all of its classes (ui-hover, and so on).
I overlooked, that I rewrite the whole section with that functions, that also redraws the table.