You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Anjali Abraham <an...@aztec.soft.net> on 2005/09/15 07:53:49 UTC
Need help on How to do sorting on table column header
Hi All,
I have a table in my page, with all its column header's to be of
link type, and when clicking on those column header link's I need to do
sorting on that particular column data of the table using tapestry. I use
tapestry4.0v.
Please respond with solutions.....
Thanks in advance,
Regards,
Anjali
Re: Need help on How to do sorting on table column header
Posted by Will Scheidegger <wi...@mac.com>.
I've implemented a rather complex setup, which is very easy to use
though. In my page which contains the list, I have a method
"sortByAttributeList(...)":
public void sortByAttributeList(String[] attributes, int
sortOrderOperator) {
ArrayList sortOrders = new ArrayList();
for (int i=0; i<attributes.length; i++) {
sortOrders.add(new SortOrder(attributes[i], sortOrderOperator));
}
Comparator sortOrder;
if (sortOrders.size() > 1) {
sortOrder = new ComplexSortOrder(sortOrders);
} else if (sortOrders.size() > 0) {
sortOrder = (SortOrder) sortOrders.get(0);
} else {
sortOrder = null;
}
if (sortOrder != null) {
getListHandler().setSortOrder(sortOrder);
getListHandler().sort();
}
}
The top part of this method converts the list of attributes and the
sort order into a java.util.Comparator object (i.e. a custom class
implementing the java.util.Comparator interface). This Comparator is
then applied to the list in the bottom part of the method
The ListHandler class (see getListHandler()) simply encapsulates the
list to display and adds a few additional features (filtering, sorting,
pagination). It's sort() method does the following:
public void sort() {
if (sortOrder != null) {
batchIndex = 1;
displayedObjects = null;
Collections.sort(getAllObjects(), sortOrder);
}
}
It checks for a sort order and sorts the list accordingly using the
java.util.Collections class.
So as a management summary:
1. Create an object implementing the java.util.Comparator interface
which compares the attributes you would like to sort.
2. Apply this object to the list unsing the
java.util.Collections.sort() method.
Good luck.
-Will
On 15.09.2005, at 07:53, Anjali Abraham wrote:
> Hi All,
> I have a table in my page, with all its column header's to
> be of
> link type, and when clicking on those column header link's I need to do
> sorting on that particular column data of the table using tapestry. I
> use
> tapestry4.0v.
>
> Please respond with solutions.....
> Thanks in advance,
>
> Regards,
> Anjali
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org