aspose file tools*
The moose likes Java in General and the fly likes Sorting multiple colums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sorting multiple colums" Watch "Sorting multiple colums" New topic
Author

Sorting multiple colums

Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
Hi everyone,

I have a list of appointments that the user will want to sort in various ways but the primary sort will always be appointment time (ascending). So for example say they want to sort by patient name I want it to look like this:

10:00 AM Jones, Bob
10:20 AM Jones, Bob
10:00 AM Smith, Fred
10:20 AM Smith, Fred

etc.

Additionally the user may sort patient name descending but still I always want appointment time ascending.

10:00 AM Smith, Fred
10:20 AM Smith, Fred
10:00 AM Jones, Bob
10:20 AM Jones, Bob

Any ideas on how I could do this?

TIA
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Is that data in a TableModel? Or a collection of domain objects? Or...?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
It's just a list of beans that get sorted on a web page.

TIA
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Without knowing more, I'd probably look at the Composite design pattern for chaining several Comparators. Does that help?
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
For anyone looking for a similar solution. I remembered commons cookbook. You can do this easily with BeanUtils and commons Collections.

example:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting multiple colums