Click to See Complete Forum and Search --> : How to add an interactive sort option to tables


mwahaha
12-09-2005, 06:58 PM
Can anyone help me add an interactive sort option to an html table? I probably don't need step-by-step help, just someone to guide me in the right direction by telling me what I need to start looking into.

Thanks in advance.

the tree
12-10-2005, 05:11 AM
Although this could be done with a big chunk of Javascript, I'd recomend a server-side process any day. Where to start depends on how your getting the infomation into your table (from a database? an xml file?)

mwahaha
12-10-2005, 12:18 PM
Yeah, I have either an xml file or a txt file.

the tree
12-10-2005, 12:41 PM
You have either? What an odd thing to say.

mwahaha
12-10-2005, 08:36 PM
Why is that odd? The person I'm making this table for has sent it to me in both forms. I haven't started yet.

ray326
12-10-2005, 11:41 PM
Since nothing has been said about what server side capacity you have I'll tell you what I'd do on a Javaserver. I'd parse the xml file into some type of ordered collection and store that in the user's session. I'd create several comparators for the objects in the collection that produce the correct set of sorts. I'd handle a "resort" by creating a new ordered collection with the desired comparator, copy the current collection into the new one (sorts it automatically) then replace the collection in the session with the new and and forward back to the JSP to display it.

You can sort HTML table rows using the DOM but it's at least an order of magnitude easier to do it on the server.