Despite the advent of broadband excessive round-trips to the server still slow websites down. Having to send a request to the server to get the same data again but in a different order each time someone wants to sort a table is just not efficient. Hence, what you want is some nice simple JavaScript to do it for you. Ideally this JavaScript should be cross-browser and should not require you to make any substantive changes to your mark-up. Well, the good news is that this ideal has been realized and has been released under the free and open source MIT License. I’m talking about Stuart Langridge’s Sorttable.

Assuming you use proper XHTML markup for your tables, in particluar thead and tbody tags, making your tables sortable is a two-step process:

  1. Include sorttable.js
  2. Set the class of the tables you want sortable to sortable

For a basic setup that’s it! If you want to get a little more fancy you can by doing things like making some columns un-sortable but that too is trivially easy. Honestly, I have no complaints at all about this script, it just works!

Technorati Tags: , , ,