Page 2 of 2

Re: Sorting collections

Posted: Fri Jun 22, 2012 12:52 pm
by timmeh
Okay I resolved this last issue by using a subclass of Array with the Any type, and a if statement to typecast values =]

Re: Sorting collections

Posted: Fri Jun 22, 2012 12:58 pm
by murray
I'd go with 7 String keys on the ExtKeyDynaDict, and then if they've only chosen 3 of 7 sort options, set the remaining key values to a null string as you don't care about the sort ordering from that point onwards.

Then, when you're deciding what to use for each of the 7 string key parameters to the putAtKey, you can "generate" a string key from the underlying data in a format that will sort correctly regardless of the type of data that is actually in that column.

Cheers,
BeeJay.
I tried this just now which is almost perfect although it breaks on timestamps, as it sorts them as a string value and 01/01/2012 is lower then 10/01/1999
Try using TimeStamp::literalFormat().

Re: Sorting collections

Posted: Fri Jun 22, 2012 2:56 pm
by BeeJay
I tried this just now which is almost perfect although it breaks on timestamps, as it sorts them as a string value and 01/01/2012 is lower then 10/01/1999
That's what I meant by
you can "generate" a string key from the underlying data in a format that will sort correctly
For TimeStamps, and other similarly affected values, I don't just type-cast to a String but rather use a formatted string that will sort correctly.

eg: Suppose you have a TimeStamp in a local variable called someTS, the first option would potentially not sort correctly, but the 2nd and third options would sort correctly:

Code: Select all

theKey := someTS.String; dynaDict.putAtKey( theKey, someObject ); theKey := someTS.Date.format("yyyyMMdd") & " " & someTS.Time.format("HH:mm:ss"); dynaDict.putAtKey( theKey, someObject ); // The following only works if you've defined a Short Date format and Short Time format called ShortDateSortingFormat and ShortTimeSortingFormat respectively: theKey := someTS.Date.userFormat($ShortDateSortingFormat) & " " & someTS.Time.userFormat($ShortTimeSortingFormat); dynaDict.putAtKey( theKey, someObject );
Here's what the ShortDateSortingFormat and ShortTimeSortingFormat definitions look like:
ShortDateSortingFormat.png
ShortDateSortingFormat.png (11.21 KiB) Viewed 6470 times
ShortTimeSortingFormat.png
ShortTimeSortingFormat.png (11.44 KiB) Viewed 6470 times
Cheers,
BeeJay.

Re: Sorting collections

Posted: Mon Jun 25, 2012 8:58 am
by JohnP
Similarly, Integers will need to be standardised to a 10-digit length, so that 100 sorts higher than 99.

Re: Sorting collections

Posted: Wed Jun 27, 2012 1:09 pm
by timmeh
cheers for the clarification, all works really well now.

Thanks again!