I took an html table that I am applying alternative row colors to, and I added jquery table sorter on it so users can sort the table.
The issue is that the alternative row colors are all messed up now as (based on the sorting) there are multiple rows with the same background color.
Is there any way to reset the alternative row color with jquery table sorter?
Via your css:
Based on Anthony's answer, but rephrased as a one-liner (mostly):
JQuery calls can be "chained" as above, using operations like
filter()
to limit the selected elements, and.end()
to "reset" to the last selection. Put another way, each.end()
"undoes" the previous.filter()
. The final.end()
is left off, since there's nothing to do after that.Revised and Latest working solution - inbuilt *This will also enable the change of colour on click.*
Now everything should kick itself out !
In order to maintain the zebra stripes after a sort has taken place you need to trigger the zebra widget again.
This is less of a hack, as you will be reusing the logic of the zebra widget rather than replicating it.
Note: This kind of work-around is only required in instances where the default zebra widget is failing. I have found in most circumstances that this hack is not required as the widget is operating correctly post sort.
How about:
Oh, and if you want a really simple fix, you could hold your breath for this CSS pseudo-class to get picked up by all the major browsers:
But my guess is based on how FF and company handle CSS for dynamic HTML, it would set your stripes onload, but not apply the CSS after you sort. But I'd like to know for sure.
There's already a default widget
zebra
, built into the core, which applies the classesodd
andeven
to alternate rows. It works whether or not you have addedclass=even/odd
to the html file.It's really easy to set up. I simply followed the instructions on the table sorter website, and then modified the document ready function to the following:
I made an example while answering the question. You can view the result in action, or see the example code.