Ian Bicking: the old part of his blog

Javascript Convert...?

I never like Javascript. Still don't. But I still find myself drawn to DHTML in interfaces. It's more responsive, and frequently a lot easier to implement (even if I'm still a Javascript novice).

Most recently I used sorttable in a project. It was far easier to implement than a server-side sorting, especially if you want to sort orthogonally from search terms or other selectors, or handle multiple sortable tables in the same page. And it gives a better user experience to boot. I'm not sure about the browser compatibility, but the application already has high browser requirements (since it include a WYSIWYG editor) so I'm not too concerned.

Since I'm still a server-side programmer, I made a few extensions to make it easier to customize. You can add a sortval attribute to a table cell, which will be used for sorting instead of the contents of the cell, and a sortsuppress="1" attribute to column headers to suppress sorting on that cell. This way I can use nicely-formatted dates like "Yesterday, 8:42am" in my cells, but put the timestamp in the sortval attribute to sort on. The modified code is here.

I'm very pleased with the result. Cheers to Stuart Langridge for a nice bit of code. (His expandable tree code was also helpful)

Created 05 Nov '03
Modified 14 Dec '04