Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting multiple colums

 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that data in a TableModel? Or a collection of domain objects? Or...?
 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a list of beans that get sorted on a web page.

TIA
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing more, I'd probably look at the Composite design pattern for chaining several Comparators. Does that help?
 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For anyone looking for a similar solution. I remembered commons cookbook. You can do this easily with BeanUtils and commons Collections.

example:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic