Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting and Reverse Sorting  RSS feed

 
r rafanan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I set up a jsp page where a collection of items are displayed in a table.
I successfully made sorting each column of information in the vector possible using Collection.sort.


Problem:
I click on the link, and everything sorts correctly. I want the reverse sort functionality.

Question and Example Scenario:

Say I sort the column by name. I click once, and it sorts in Ascending order. I click the same link again and sorts in descending order.

I got the functionality to sort on ascending order, but have a tough time trying to figure out.

How do I make it where every click of the same link alternates actions (alternates sorting alphabetically, then clicking again sorts in reverse alphabetical order)?

Do I have to store a temporary session variable somewhere to make this work?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chnage the link each time it is clicked. eg date=asc, and after they click on that make it date=desc
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in this case, every time there is a click, the client will make a server request.

Wouldnt it be more efficient/ better user experience to code some Javascript to do the sorting and reverse sorting?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article and this article discuss sorting tables in ascending and descending order on the client using DOM and JavaScript.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!