WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Coloring selected columns dynamically with sortable table, Adrian, February 22, 2005

Subject: Coloring selected columns dynamically with sortable table From: Adrian Date: February 22, 2005
I have a table which is sortable using sortabletable.js. I would like to be able to click on the header cell, and have that column sorted along with the cells of that column to be colored based on value.

I managed to write a function that can do that via a link, but don't know how to do it by clicking on the header.

Here's my function:

function highlight(col) {
// Highlight selected column
var row = document.getElementById("census").rows;

for (i=1; i < row.length; i++) {
var y = row[i].cells;
var value = row[i].cells[col].innerHTML;
switch (col) {
case 4:
if (value < 7) {
y[col].style.background = "#CCFFCC";
}
else if (value < 9) {
y[col].style.background = "#FFFFCC";
}
else
y[col].style.background = "#FFCCCC";
break;
case 5:
if (value < 70) {
y[col].style.background = "#CCFFCC";
}
else if (value < 100) {
y[col].style.background = "#FFFFCC";
}
else
y[col].style.background = "#FFCCCC";
break;
case 6:
if (value == "yes") {
y[col].style.background = "#CCFFCC";
}
else
y[col].style.background = "#FFCCCC";
break;
default:
y[col].style.background = "#FFFFFF";
}

}
}


Thanks.



Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX