Providing links in column headers for users to sort data

Providing links in column headers for users to sort data

My problem is as follows: I have a JSP file which will render an XML file in tabular format. The XML file is the pre-formatted database query result. In the column header of the table, I want to provide links which can be clicked by the user in order to sort the column. How can I do that effectively? Since the XML is already in the client space, I am thinking about doing the sorting using JavaScript. Another option is to generate another request to the server component, which will return the sorted XML file (but it means I have to do a database query). Thanks very much.

    Requires Free Membership to View

    When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to keep you informed on recent service-oriented architecture (SOA) and SOA-related topics such as integration, governance, Web services, Cloud and more.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSOA.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSOA.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

One very handy mechanism that I have seen employed for this very situation is the use of value objects that implement a Sortable interface exposing a public method as follows:

public interface Sortable
{
   int compare(Object object, String field);
}
The value objects also implement an interface identifying them as able to import and export XML, such as the following:
public interface XMLCapable
{
   public String toXML();

   public void fromXML(String xml);
}
With the value objects implementing these interfaces, a template engine such as JSP can sort the value objects on whatever field is desired. The links in the HTML response can target the host with a request to re-sort the columns.

This solution, of course, performs the sort before the template is rendered to the client's space. I believe you are on the right track by presuming JavaScript as the mechanism for a client-space solution.


This was first published in March 2003