简体   繁体   English

对表格进行排序后,表格行中的备用行颜色不起作用

[英]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.我正在使用具有交替行颜色的表,并且同一个表具有 jquery.tablesorter.js 的排序功能。 as follow.如下。

css can be applied for alternative row like. css 可用于替代行之类的。

              $("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.任何帮助将不胜感激。

Use the zebra widget:使用斑马小部件:

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

after sort completed you can run this jquery code:排序完成后,您可以运行此 jquery 代码:

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

Here is the jsFiddler code .这是jsFiddler 代码

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'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM