EGHDK
EGHDK

Reputation: 18130

Tablesorter JS Cannot implement odd/even

I'm trying to implement the odd even and blue theme to replicate the demo.

I have everything working:

The only thing that doesn't work is the odd and even coloring of each row. This is my .

<head>
<script type="text/javascript" src="jquery-latest.js"></script> 
<script type="text/javascript" src="jquery.tablesorter.js">
 </script> 
<link rel="stylesheet" href="style.css" type="text/css" media="print, projection, screen" />

<script type="text/javascript">
$("#myTable").tablesorter({widgets: ['zebra']});

    </script>
</head>

I hard coded the header class for the headers, but I tried to write a function to set the class to odd and even, but when I sort the table, the rows mess up. Example: 3 light 1 dark 4 light 2 dark

I'm guessing it has to do with zebra, and I tried searching SO and the documentation but I came up empty.

Upvotes: 1

Views: 182

Answers (1)

Mike Robinson
Mike Robinson

Reputation: 25159

No need to do this with classes any more. Just use CSS!

#myTable tr {
  background: red;
}

#myTable tr:nth-child(odd) {
  background: blue;
}

This is supported by IE9+ and other major browsers: http://caniuse.com/#search=nth-child

Upvotes: 2

Related Questions