Soring break row color background
Soring break row color background
rishabdragon
Posts: 1Questions: 0Answers: 0
Hi Experts,
Need your expert help to complete last change in a Job.
Other than DataTable filters, I have my own custom filters also. And based on filters I am able to set rows alternate active class "even"or "odd" on alternate basis.
Like
var DataTableOrderItemsrows = $('#gvOrderItems').dataTable().fnGetNodes(); // 'gvOrderItems' is datatable name
var flagRowAlternate = false;
for (var i = 0; i < DataTableOrderItemsrows.length; i++) {
if (some condittion) {
$(DataTableOrderItemsrows[i]).show();
//logic to set aleternate row color
if (flagRowAlternate) {
$(DataTableOrderItemsrows[i]).removeClass("even odd").addClass("odd");
flagRowAlternate = false;
}
else {
$(DataTableOrderItemsrows[i]).removeClass("even odd").addClass("even");
flagRowAlternate = true;
}
}
else { // if condition false
$(DataTableOrderItemsrows[i]).hide();
}
} // end for loop
The out put is like this:
..
..
..
..
..
It works fine.
But here is the real problem, it does not work with Datatable "Sort". The row alternate color breaks with sorting.
I found one close solutions was to use :
table.display tr.odd
{
background: none repeat scroll 0 0 #EBEBEB;
height: 27px;
}
table.display tr.even
{
background: none repeat scroll 0 0 #F7F7F7;
height: 27px;
}
But it does not work for me. Or I am not implementing it right, because datatable rows never shows this class in fire bug.
Any guidance link will be very helpful to me.
Thanks
Need your expert help to complete last change in a Job.
Other than DataTable filters, I have my own custom filters also. And based on filters I am able to set rows alternate active class "even"or "odd" on alternate basis.
Like
var DataTableOrderItemsrows = $('#gvOrderItems').dataTable().fnGetNodes(); // 'gvOrderItems' is datatable name
var flagRowAlternate = false;
for (var i = 0; i < DataTableOrderItemsrows.length; i++) {
if (some condittion) {
$(DataTableOrderItemsrows[i]).show();
//logic to set aleternate row color
if (flagRowAlternate) {
$(DataTableOrderItemsrows[i]).removeClass("even odd").addClass("odd");
flagRowAlternate = false;
}
else {
$(DataTableOrderItemsrows[i]).removeClass("even odd").addClass("even");
flagRowAlternate = true;
}
}
else { // if condition false
$(DataTableOrderItemsrows[i]).hide();
}
} // end for loop
The out put is like this:
..
..
..
..
..
It works fine.
But here is the real problem, it does not work with Datatable "Sort". The row alternate color breaks with sorting.
I found one close solutions was to use :
table.display tr.odd
{
background: none repeat scroll 0 0 #EBEBEB;
height: 27px;
}
table.display tr.even
{
background: none repeat scroll 0 0 #F7F7F7;
height: 27px;
}
But it does not work for me. Or I am not implementing it right, because datatable rows never shows this class in fire bug.
Any guidance link will be very helpful to me.
Thanks
This discussion has been closed.
Replies
You should not have to add them manually.
However, if you wish so, I guess you should add your function to fnRowCallback, otherwise it would not be taken into account when redrawing the rows after filtering or a page change.
Please link us to a test case showing the issue: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
Allan