最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - After sorting table, The alternate row color in table row is not working - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Jun 29, 2011 at 7:49 Hardik Patel asked Jun 29, 2011 at 7:00 Hardik PatelHardik Patel 9373 gold badges14 silver badges39 bronze badges 3
  • How do you color the rows? if you're using CSS's :nth-child(odd/even), it should be ok. – yoavmatchulsky Commented Jun 29, 2011 at 7:02
  • The last time I did some table sorting was a while ago, but from what I remember whichever JQuery sort routine I used did the alternate colours automatically. Perhaps if you post some of your HTML/CSS/JS? – nnnnnn Commented Jun 29, 2011 at 7:11
  • hi i am using . $("tr:even",$(this)).css({'backgroundColor':'#ffffff'}); $("tr:odd",$(this)).css({'backgroundColor':'#ebf0f5'}); – Hardik Patel Commented Jun 29, 2011 at 7:33
Add a ment  | 

3 Answers 3

Reset to default 5

Use the zebra widget:

$("table").tablesorter({widgets: ['zebra']}) 

after sort pleted you can run this jquery code:

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

Here is the jsFiddler code.

Use this:

$('#table').tablesorter({
    widgets     : ['zebra'],
    widgetZebra : {
        css: ['your_even_css_class_name', 'your_odd_css_class_name']
    }
});

And remove this:

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

评论列表(0)

  1. 暂无评论