Sort tables with sorttable.js
I’ve been enjoying listening to the “Audible Ajax” podcasts from Ajaxian lately. One of the older shows was a talk by Lugradio’s Stuart Langridge in which, in an aside, he mentioned a table sorting widget he had written. It sounded cool. When I got home I fired up the browser and found it: sorttable.js.
Even though it’s over two years old and doubtless there are a bazillion Ajax (tm) toolkits that include supersets of this functionality, I find it to be a very elegant thing. Largely that’s because of its utterly configuration-free operation. As long has you’ve put <th>
headers on your table, you just include the script in your page, and set class="sortable"
and a unique id on each of your table(s); clicking on a table header re-sorts the table by that column, without any action on the server side at all.