JavaScript table sorting
I wrote this post a while back. The content can still be relevant but the information I've linked to may not be available.
I know we are not building websites using tables for layout any more (ahem) but tables are still the best way of displaying related data. The table often pulls information from a database using an SQL query that orders the data according to one of the column data headers. For example, display some data and sort it alphabetically or perhaps in date order, either descending or ascending.
Here's a great table sorting script by Stuart Langridge that gives your website users1 the ability to click on each column header to sort the data themselves. Implementation is easy, download the script, reference it in the head of your document, add a class name to your table, and that's it. Table sorting made easy....
I have used this to make the admin section of one of my own websites much easier to manage. The table sorting script provides alternative table views without resorting to additional database calls. Cool.
1 Best practice: When using JavaScript, it is important that the script should degrade gracefully. That is, web visitors who have disabled JavaScript will still see be able to use the website and view the data. The functionality will not be there but the website still works. In this case, the data is still viewable with JavaScript turned off.
Comments
22 Jun 2007 08:44:19
Glad you liked the script. :)
Comments are OFF for this post.