listview sort datetime column

Discussions specific to Team Developer 5.1.

listview sort datetime column

Postby e.russo » Thu Oct 07, 2010 1:21 am

Hi,

I need to sort a listview colum ( double click on column header ) that contains datetime field ( format dd/MM/yyyy - I don't want to change this format).

Any idea on how to resolve this problem?

Thanks in advance


Enrico
e.russo
 
Posts: 42
Joined: Wed Jul 30, 2008 7:22 am

Re: listview sort datetime column

Postby Jeff Luther » Thu Oct 07, 2010 3:38 pm

Put a small test case together and let's find out what, if anything, is the problem. That's one good way to resolve it -- at least that's the first step.
Jeff Luther
 

Re: listview sort datetime column

Postby TerryP » Fri Oct 08, 2010 4:30 pm

Hi Enrico (and Jeff),

From the initial post, it sounds like you are asking how to implement a date/time column sort, rather than suggesting there's a problem.

The issue is that the List View column sorting only performs a text value sort, not a data type dependent sort, hence the rows don't appear in the desired order when formatted as dd/MM/yyyy.

The easiest way around this is to display the date/time value in a format to one that will sort into the desired order, e.g. yyyy-mm-dd.hh:mm:ss. However, this was mentioned as not acceptable.

A second option would be to create a hidden column (width=0) with the date/time value in that format, and then intercept the column click and trick the sort into using the hidden column rather than the visible one.

Depending on how the List View is populated in the first place, another option is to keep an array of the data values for the rows and implement your own sort mechanism, then repopulate the List View in the new order.

One final way I've done this where the List View is populated from a database query, is to dynamically change the ORDER BY clause on the SELECT command to include the appropriate column name (or number) identified by the column selected, then re-issue the query and re-populate the List View.

Of course, there may be other alternatives I haven't thought of, but I've used most of these some time in the past. Which one is the best alternative will depend on how the List View is populated in the first place and how costly it is to implement or perform the process (e.g. re-issuing the database query may or may not be the most efficient way to achieve the outcome).

I hope one of the above options is what you're after....

Cheers,
Terry Phythian
Reprise Consulting
TerryP
 
Posts: 302
Joined: Thu Oct 18, 2007 10:13 pm
Location: Brisbane, Australia


Return to Team Developer 5.1

Who is online

Users browsing this forum: No registered users and 1 guest