Sortable Tables Script
- Include the Javascript library, by
putting a link to it in the HEAD of your page, like so:
<script src="sorttable.js">
- Mark your table as a sortable one by giving it a class of
"sortable":
<table class="sortable">
- Ensure that your table has an ID:
<table class="sortable" id="unique_id">
And that's all you need. Your table will now have column sorting
available by clicking the headers. For niceness, you might want to add
the following styles to your stylesheet, or make up some of your own
based on this:
/* Sortable tables */
table.sortable a.sortheader {
background-color:#eee;
color:#666666;
font-weight: bold;
text-decoration: none;
display: block;
}
table.sortable span.sortarrow {
color: black;
text-decoration: none;
}
The Javascript library (sorttable.js):
Test the script
| Name | Salary | Extension | Start date |
| Bloggs, Fred | $12000.00 |
1353 | 18/08/2003 |
| Turvey, Kevin | $191200.00 |
2342 | 02/05/1979 |
| Mbogo, Arnold | $32010.12 |
2755 | 09/08/1998 |
| Shakespeare, Bill | $122000.00 |
3211 | 12/11/1961 |
| Shakespeare, Hamnet | $9000 |
9005 | 01/01/2002 |
| Fitz, Marvin | $3300 |
5554 | 22/05/1995 |