I have to make an html table sortable by any column. I found the following javascript library that does the trick: “sorttable: make all your tables sortable“
There is one problem: my table has alternating colors for the rows. After the sort, some adjacent rows have the same color.
Solution: After the sort, set the color to alternating colors.
var sortedRows = document.getElementsByTagName(“tr”);
for (var i=0; i<sortedRows.length; i++) {
if (i%2) { sortedRows[i].setAttribute(“bgcolor”, “white”); }
else { sortedRows[i].setAttribute(“bgcolor”, “silver”); }
}