• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting a table based on a column

 
C Vivek
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys!

Ive got a table displayed in my JSP. If I would like to sort the table based on say ascending order or date or name etc how do I do it.

Yours hints would be much appreciated.

Thanks in advance.

Vivek
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you fetching the stuff from a database ? You could use the order by clause to do this work. Call the servlet every time you want to order the information or cache the stuff into a data structure and sort it there with comparators as required. You can then attach the structure into session scope or any other scope and display the info.
 
Praveen Reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using MVC model then display tag works fine for you

For More Information on Display tag Click Here
 
C Vivek
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys,

Is it a good Idea to fetch data from the database for sorting a column in a view?

I put an object into an ArrayList. But how do I sort an ArrayList if it takes objects. I know Comparator is used in Java5 but how do it if I have Java1.4

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's best to have the database do the sorting.
[ May 20, 2007: Message edited by: Bear Bibeault ]
 
C Vivek
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
It's best to have the database do the sorting.

[ May 20, 2007: Message edited by: Bear Bibeault ]


Bear,
Would that not be a performance hit? If I would like to sort a table in Ascending or descending order of any of the columns. Then is it not advisable to work on the List instead of database?

Thanks in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Databases are optimizzed for that sort of thing. Sorting in the database will usually be much more efficient that sorting it after the fact -- especially if the database is well-tended and correcttly tuned.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!