Another approach is to have the column property set to your date property, so the sorting will be done on the Date object, NOT on the string representation of the date, then either write a decorator to transform the date appropriately or use the JSTL fmt:formatDate tag, something like this:
<display:column property="date" sortable="true" title="Date"> <fmt:formatDate value="${item.date}" pattern="xxx" /> </display:column> All of the formatDate stuff is left to your investigation... I prefer the JSTL method, since it doesn't require code changes to modify the output. Those tags also have localization options, but I haven't used those. Chaudhary, Harsh wrote: > To follow up on Kathryn's post, I tried the sortproperty with dates and > that works too. So, if you do not want to write your own comparator, you > can do this: > - Add a field to your object like if currently you have String > dateString, add a field Date date and use the SimpleDateFormat class to > convert your String date to a Date object. > - Then, in the display tag definition, do this: > > <display:table name="list" defaultsort="1" defaultorder="descending"> > <display:column property="dateString" sortable="true" title="Date > Column Header" sortProperty="date"/> > </display:table> > > This should work. > > Good luck, > HC. > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Jones, Kathryn K - IT ADS > Sent: Friday, December 08, 2006 8:41 AM > To: Venkatesh D > Cc: displaytag-user@lists.sourceforge.net > Subject: Re: [displaytag-user] Sorting Issues > > > You can add another if clause in the comparator class that I posted a > few days back, to parse the two strings into Dates and return Date's > compareTo(). Or, you could write your own custom comparator. > > I think you can also use two variables, with the display as String and > the underlying sort as Date, and use the sortProperty like another > poster did with numbers, but I am not 100% sure if that works with > dates. > > > Kathryn K. Jones > Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > > > _____ > > From: Venkatesh D [mailto:[EMAIL PROTECTED] > Sent: Friday, December 08, 2006 12:20 AM > To: Jones, Kathryn K - IT ADS > Subject: Re: [displaytag-user] Sorting Issues > > > Hai , > I am using displaytag library .By using that I am displaying > date in some datecolumn.When I am sorting that column it is unable to > sort the dates in particular > > order.It comes in random order but not in ascending or descending .The > problem is ,in display tag sorting happens by character data.I am not > able to sort date.Please help me in this matter > > Thanx in advance > > > Venkatesh D > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________ > displaytag-user mailing list > displaytag-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/displaytag-user > -- Rick Herrick [EMAIL PROTECTED] Proud member of the reality-based community Never try to discourage thinking for you are sure to succeed.--Bertrand Russell ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ displaytag-user mailing list displaytag-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/displaytag-user