# calling a method within a sort

**URL:** <https://forum.servoy.com/t/calling-a-method-within-a-sort/3340>\
**Category:** Classic Servoy\
**Created:** [January 1, 2005, 1:50am UTC](https://forum.servoy.com/t/calling-a-method-within-a-sort/3340 "2005-01-01T01:50:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobcart](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@bobcart](https://forum.servoy.com/u/bobcart)\
**Post date:** [January 1, 2005, 1:50am UTC](https://forum.servoy.com/t/calling-a-method-within-a-sort/3340/1 "2005-01-01T01:50:21Z")

</div>

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:

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

```

Here’s the TextSrt method:

```auto
// 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

---

<div class="post-metadata">

**Author:** ![bobcart](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@bobcart](https://forum.servoy.com/u/bobcart)\
**Post date:** [January 1, 2005, 6:23am UTC](https://forum.servoy.com/t/calling-a-method-within-a-sort/3340/2 "2005-01-01T06:23:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jan\_Aleman](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jan\_Aleman](https://forum.servoy.com/u/Jan_Aleman)\
**Post date:** [January 1, 2005, 6:41pm UTC](https://forum.servoy.com/t/calling-a-method-within-a-sort/3340/3 "2005-01-01T18:41:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bobcart](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@bobcart](https://forum.servoy.com/u/bobcart)\
**Post date:** [January 1, 2005, 7:36pm UTC](https://forum.servoy.com/t/calling-a-method-within-a-sort/3340/4 "2005-01-01T19:36:16Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![bobcart](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@bobcart](https://forum.servoy.com/u/bobcart)\
**Post date:** [January 11, 2005, 11:43pm UTC](https://forum.servoy.com/t/calling-a-method-within-a-sort/3340/5 "2005-01-11T23:43:15Z")

</div>

> 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](http://forum.servoy.com/viewtopic.php?t=3650)
