Help to color-alternate rows in sortable table

ⅰ亾dé卋堺 提交于 2019-12-02 10:07:53

Tablesorter has a built in function to "zebra" stripe the rows, it also automatically updates the striping after sorting. Use it as follows:

CSS

.NormRow { background-color: #fbfbfb; }
.AltRow  { background-color: #ddd; }

Script

$('#packageTbl').tablesorter({
   widgets: ['zebra'],
   widgetZebra: {css: ["NormRow","AltRow"]} // css classes to apply to rows
});

Update: Actually, the default CSS the tablesorter uses is "odd" and "even" so change the css names to that if you wish.

JavaScript:

$('.tablesorter tr:nth-child(odd)').addClass('odd');

CSS:

.odd {
    background-color:#FBFBFB;
}

Example can be found here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!