Custom Sorting
Posted by Theo Heselmans on August 1st, 2007
I needed to sort a list, based on a user-defined sorting order.
You see this kind of sorting also in Excel
(look in 'Options' and 'Custom Lists' to see examples).
@Sort has, as of version 6, a great new way of custom sorting.
Look at the following example:
Order:="Jan":"Feb":"Mar":"Apr":"May":"Jun":"Jul":"Aug":"Sep":"Oct":"Nov":"Dec";
Unsorted:="Feb":"Dec":"Oct":"Feb":"TTT":"Jan";
Sorted:=@Sort(Unsorted;[CustomSort];
@If(
@Member($A;Order) < @Member($B;Order);-1;
@Member($A;Order) > @Member($B;Order);1;
0)
);
@Prompt([OK];"Sort based on List";
"Unsorted: "+@Implode(Unsorted;", ")+
@NewLine+
"Sorted: "+@Implode(Sorted;", ")
);
Unsorted:="Feb":"Dec":"Oct":"Feb":"TTT":"Jan";
Sorted:=@Sort(Unsorted;[CustomSort];
@If(
@Member($A;Order) < @Member($B;Order);-1;
@Member($A;Order) > @Member($B;Order);1;
0)
);
@Prompt([OK];"Sort based on List";
"Unsorted: "+@Implode(Unsorted;", ")+
@NewLine+
"Sorted: "+@Implode(Sorted;", ")
);
Give it a try: paste the code above in an agent and run it:
Note that "TTT" does not occur in the Order-list, and since @Member returns a 0 when the value is not found, "TTT" will show up first in the sorted list.
Pretty neat, isn't it ?
Category: Domino/Notes | Technorati: Show-n-Tell Thursday, SnTT
Comments (2)
Good morning Theo.
Nice custom sort.
A few of us got a bit silly and really played with @Sort a couple of years back, you might be interested in taking a look:
{ Link }
PS: Are you planning on attending Lotuspshere 2008?
-Devin.
@Devin
Indeed, nice 'playing'.
I should dig into @transform too. I Hardly ever use/need it.
And Yes I'm going to LS2008 (it will be my 13th LS ;-)