SnTT.jpgI 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;", ")
);

Give it a try: paste the code above in an agent and run it:
Image:Custom Sorting
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  | TechnoratiTechnorati: ,