- Apr
- 25
- 2007
Make a Table Sortable in 30 Seconds or Less
By: Robert Dempsey | Tags:The task: sort a table without a trip to the server.
After reading a great article on MochiKit in LinuxJournal, and decided it may be the best way to go. After two hours of unsuccessfully trying to get the sortable_tables.js script to sort tables in my Rails (1.2.3) app, I went back to Google. I searched for “javascript sort table” and found this lovely little bit of JS. After I downloaded it into my javascripts directory, I did the following:
- Added ’sorttable’ to my javascript_include_tag (in my layout)
- Added class=”sortable” to my table
- Ensured that each table header was all by itself (i.e. no colspan=”2″)
- Refreshed my browser
- Sat back, smiled, and got another cup of coffee
My search of the forums suggests that MochiKit and Prototype don’t play well together. Some forums say they do. To be fair, the only function of MochiKit I was trying to use was the sortable_tables.js script. Inside of my Rails app, Firebug didn’t like it too much; but off the Rails, the script works flawlessly. I also think it a good idea to mention that I am not paginating my results - we are keeping it simple.
For another great table sorting script that is even more robust check out this one over at the Fried Cell Collective.
If you have experience getting MochiKit to work with Rails let us know! It looks rockin and we want to use it :).
Share this post
Random Goodness
You can leave a response, or trackback from your own site.


One Response to “Make a Table Sortable in 30 Seconds or Less”
On August 4th, 2008 at 3:30 pm Adam said:
Have you tried this library on a secure page? We keep getting ‘This page contains both secure and nonsecure items’ (on IE)
I’ve just started looking into it, but if you have any ideas, I’d love to hear them.