Bluehost: Web hosting from $3.95/month. Sign Up

JavaScript table sorting

Posted on by Clive Walker in Web Development JavaScript

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.

Technorati :

Comments

Leave a comment

A simple question that helps prevent automated form fillers.

© 2016 Clive Walker