HTML Table
HTML
<table id="codexpl">
<thead>
<tr>
<th>#</th>
<th><span >98</span></th>
<th><span id="vertical">A_LONG_HEADER</span></th>
</tr>
</thead>
<tr>
<td>1</td>
<td>This</td>
<td>c</td>
</tr>
<tr>
<td>2</td>
<td>6</td>
<td>two</td>
</tr>
<tr>
<td>3</td>
<td>is</td>
<td>not</td>
</tr>
<tr>
<td>4</td>
<td>the</td>
<td>Column</td>
</tr>
<tr>
<td>5</td>
<td>first</td>
<td>One</td>
</tr>
</table>
<p>TEST</p>
CSS
#codexpl th, #codexpl td{
padding:0.8em;
border: 1px solid;
}
#codexpl th{
background-color:#6699FF;
font-weight:bold;
}
thead th {
height: 130px;
}
#vertical{
writing-mode: vertical-rl;
text-orientation: mixed;
}
JavaScript
//This passed array contains the row order
function movedarows(tbl,arr){
numofrows = tbl.getElementsByTagName('tr').length;
remed = new Array();
var tbody = tbl.tBodies[0];
for(i=1;i<numofrows;i++){
remed.push(tbody.rows[i].cloneNode(true));
}
for(i=0;i<remed.length;i++){
tbody.replaceChild(remed[i], tbody.rows[arr[i]+1]);
}
}
function compare(a,b){
if(a == b){
return 0;
}//Check for condition a.isNaN and b.isNum
//nums go before letters
else if(isNaN(a) && !isNaN(b)){
//a goes after b
return 1;
}else if(!isNaN(a) && isNaN(b)){
return (-1);
}//Both not nums
else if(!isNaN(a) && !isNaN(b)){
return a-b;
}//If both are words
else{
as = a.toLowerCase();
bs = b.toLowerCase();
return (as < bs) ? -1 : ((as > bs) ? 1 : 0);
}
}
function sorttable(tbl, colnum){
/*
This function returns an array of str indexed
as seen in the Table
*/
numofcols = tbl.getElementsByTagName('th').length;
numofrows = tbl.getElementsByTagName('tr').length;
sorted = new Array();
if(numofcols < colnum){
throw "Invalid Column number"
}else{
for(i=1; i<numofrows; i++){
trel = tbl.getElementsByTagName('tr')[i];
tdel = trel.getElementsByTagName('td')[colnum];
for(j=(i+1);j<numofrows; j++){
trel2 = tbl.getElementsByTagName('tr')[j];
tdel2 = trel2.getElementsByTagName('td')[colnum];
if(compare(tdel.innerHTML, tdel2.innerHTML) < 0){
if(sorted[i-1] == undefined){sorted[i-1]=0;}
if(sorted[j-1] == undefined){sorted[j-1]=0;}
//sorted[i-1] += (-1);
sorted[j-1] += 1;
}else if(compare(tdel.innerHTML, tdel2.innerHTML) > 0){
if(sorted[i-1] == undefined){sorted[i-1]=0;}
if(sorted[j-1] == undefined){sorted[j-1]=0;}
sorted[i-1] += 1;
...