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: , , ,

Comments

4 Responses to “Simple Sortable Tables”

  1. Dave Cahill on July 5th, 2007 9:45 pm

    Yeah, I used this one on a project a while back, does the job well.

  2. sicapitan on July 12th, 2007 3:19 am

    Great I’ve been looking for something like this :)

  3. Julie O'Hara on November 26th, 2007 7:47 am

    This is exacly what I want. I use iWeb to develop my site. iWeb allows you to add HTML snippets but I don’t know how I would access the Head for a page in order to put a link to the Javascript there.

    Do you have specific suggestions for iWeb users?
    Thanks so much.

    Love your site, by the way.

  4. Bart B on November 26th, 2007 12:18 pm

    Hi Julie,

    Thanks for your kind comments. I don’t have much experience with iWeb. I tried it once and hated it. Never went back. As you get more into web development the time will come when you want total control of your source. At that point you have out-grown iWeb. Maybe that time has come for you?

    Sorry I can’t be or more help,

    Bart.

Leave a Reply




Before you post a comment please remember that commenting on my blog is a privilege not a right. I won't approve comments that are obscene, offensive or insulting. For more info please read this post.

Subscribe without commenting