Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After sorting table, The alternate row color in table row is not working

i am using a table with alternate row color and the same table has sorting functionality with jquery.tablesorter.js. as follow.

css can be applied for alternative row like.

              $("tr:even",$(this)).css({'backgroundColor':'#ffffff'});
              $("tr:odd",$(this)).css({'backgroundColor':'#ebf0f5'});

sorting can be done by

             function sortTable(tableID)
                {
                     $("#"+tableID).tablesorter();      
                }

First time alternative row color works fine.

But When I sort the records the format has been changed. and alternative row color is not working.

Any help will be appreciated.

like image 388
Hardik Patel Avatar asked Dec 04 '25 21:12

Hardik Patel


2 Answers

Use the zebra widget:

$("table").tablesorter({widgets: ['zebra']}) 
like image 68
Sjoerd Avatar answered Dec 06 '25 12:12

Sjoerd


after sort completed you can run this jquery code:

$("table <make it more specific!>").find("tr").removeClass("alt").filter(":odd").addClass("alt");

Here is the jsFiddler code.

like image 35
Mo Valipour Avatar answered Dec 06 '25 12:12

Mo Valipour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!