Note: I would have used Array.prototype.slice instead of Array.prototype.filter, but the former had error issues with IE for some obscure reason, and I didn't feel like overriding the method.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="33%" align="center"><u><b>Name</b></u></td>
<td width="33%" align="center"><u><b>Age</b></u></td>
<td width="34%" align="center"><u><b>Date</b></u></td>
</tr>
<tr>
<td width="33%">John</td>
<td width="33%">48</td>
<td width="34%">13</td>
</tr>
<tr>
<td width="33%">George</td>
<td width="33%">52</td>
<td width="34%">6</td>
</tr>
<tr>
<td width="33%">Jack</td>
<td width="33%">39</td>
<td width="34%">22</td>
</tr>
</table>
<script type="text/javascript">
if(!Array.prototype.forEach) {
Array.prototype.forEach = function(f /*, context*/) {
for(var i = 0, n = this.length, t = arguments[1]; i < n; ++i)
f.call(t, this[i], i, this);
};
}
if(!Array.prototype.filter) {
Array.prototype.filter = function(f /*, context*/) {
for(var i = 0, n = this.length, r = [], t = arguments[1], v; i < n; ++i)
if(f.call(t, v = this[i], i, this))
r.push(v);
return r;
};
}
Array.prototype.filter.call(
document.getElementById("AutoNumber1").getElementsByTagName("tr"),
function(x, i) {return i != 0;}
).sort(
function(a, b) {
a = a.getElementsByTagName("td")[2].firstChild.nodeValue - 0;
b = b.getElementsByTagName("td")[2].firstChild.nodeValue - 0;
if(a < b)
return -1;
if(a > b)
return 1;
return 0;
}
).forEach(function(x) {
x.parentNode.appendChild(x);
});
</script>
</div>
</body>
</html>
Bookmarks