calling a method within a sort

I’d like to sort a text field but not in alphabetical order. For example, I want a field named ‘priority’ with values of High, Med, or Low ordered such that High is first and Low last.

I’d like to create a method that knows how to sort each field and just call it as a parameter in the sort command. I’ve played with this a bit but I’m not having any luck. Here’s an example of the kind of thing I have tried.

Here’s the sort method:

// sort that uses a special text sort method
controller.sort('TextSrt(priority) asc');

Here’s the TextSrt method:

// determines a custom sort order number for text fields
switch (arguments[0])
{
	case 'High': srt = 1;
		break;
	case 'Med': srt = 2;
		break;
	case 'Low': srt = 2;
}
return srt;

When I try this, the sort doesn’t seem to execute the method. Is my syntax wrong or does sort simply not support this?

Yes, I could add a sort order column and compute a custom sort order easy enough, but I have many of these, and it is less flexible, time consuming and requires more maintenance to use all these extra columns.

Any clues appreciated.

Bob

In thinking more about this, it seems likely that servoy isn’t doing the sort, but just sending an 'order command to the the back end db. Doing it any other way would just be too slow.

However, that still doesn’t give me the answer I need. Until I hear a better idea, I’m off creating lots of columns for storing the sort numbers I need.

You don’t need to create extra columns. The right way to do it is store priority as a number and map it in a valuelist to the label you want to display.

jaleman:
You don’t need to create extra columns. The right way to do it is store priority as a number and map it in a valuelist to the label you want to display.

Excellent, Jan! That’s a very nice trick. Thank you much!

jaleman:
You don’t need to create extra columns. The right way to do it is store priority as a number and map it in a valuelist to the label you want to display.

For those following this, I tried this approach, but ran into issues on searches. See this:
http://forum.servoy.com/viewtopic.php?t=3650