bDeferRender and fnRowCallback

bDeferRender and fnRowCallback

dorothyjjohnsondorothyjjohnson Posts: 8Questions: 0Answers: 0
edited November 2012 in General
I have a table that assigns colors to cells based on the content. It works well without bDeferRender, but with bDeferRender when the table is sorted on that column the coloring is lost. Without bDeferRender the table is much slower to load in IE. Any suggestions?

[code]
var oTable = $('.dataTable').dataTable({
"sAjaxSource": '../include/intage_ajax.html',
"bJQueryUI": true,
"sDom": 'rt<"F"ip<"clear">T>',
"bDeferRender": true,
"sScrollY": '550px',
"sPaginationType": "full_numbers",
"bScrollCollapse": true,
"oTableTools": $.planning.oTableTools,
"iDisplayLength": 25,
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var count = aData[2];
var class_name = 'green-bg';
if (count > 150) {
class_name = 'red-bg';
} else if (count > 90) {
class_name = 'yellow-bg';
}
// Remove column sorting background color.
$('td:eq(2)', nRow).removeClass('sorting_1');
$('td:eq(2)', nRow).removeClass('sorting_2');
$('td:eq(2)', nRow).removeClass('sorting_3');
$('td:eq(2)', nRow).addClass(class_name);
return nRow;
}
});
[/code]

Replies

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Sounds odd - they really should work together okay. Could you link me to a test page showing the problem so I can debug it please?

    Allan
  • dorothyjjohnsondorothyjjohnson Posts: 8Questions: 0Answers: 0
    Thank you for your reply Allan. I created a test page here: http://live.datatables.net/igisom/2
    If you sort on Platforms the colors disappear, any other column they come back. If you remove bDeferRender you can sort on platforms and the colors stay. Thank you again for taking a look.
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Your styles are being overridden by:

    [code]
    tr.odd.gradeA td.sorting_1 {
    background-color: #C4FFC4;
    }
    [/code]

    Just remove that from the demo CSS file and it should work just fine.

    Allan
  • dorothyjjohnsondorothyjjohnson Posts: 8Questions: 0Answers: 0
    That worked thank you.

    Just out of curiosity, isn't that what $('td:eq(2)', nRow).removeClass('sorting_1'); is suppose to do?
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Yes, I can see that would be the intention, but the sorting_{} classes are actually added after fnRowCallback. So the sequence was that you were removing classes for the old draw and then DataTables was adding them for the new draw - hence the problem!

    I think I'll write an article about the sequence of the callbacks on a draw at some point - thanks for the suggestion :-).

    Allan
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    I should also say that bSortClasses can be set to false to disable the sorting_{} classes being added.
  • dorothyjjohnsondorothyjjohnson Posts: 8Questions: 0Answers: 0
    Thank you for your help.
This discussion has been closed.