# Sorting on calculated field

**URL:** <https://forum.servoy.com/t/sorting-on-calculated-field/19261>\
**Category:** Classic Servoy\
**Created:** [May 19, 2017, 8:37am UTC](https://forum.servoy.com/t/sorting-on-calculated-field/19261 "2017-05-19T08:37:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![developers10](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@developers10](https://forum.servoy.com/u/developers10)\
**Post date:** [May 19, 2017, 8:37am UTC](https://forum.servoy.com/t/sorting-on-calculated-field/19261/1 "2017-05-19T08:37:24Z")

</div>

Hi,

We have a small tableview in which we would like to show the translated description.  
This works ofcourse using a calculated field which returns the

```auto
i18n.getI18NMessage(origfield)

```

But sorting doesn’t work. Apparently we always get the tableview sorted on the origfield  
Custom onSort methods don’t work either, i’ve tried :

```auto
foundset.sort(calculated_field asc)

```

and also

```auto
controller.sort(calculated_field asc)

```

```auto
foundset.sort(function(a,b) {return i18n.getI18NMessage(a.origfield) > i18n.getI18NMessage(b.origfield);})

```

but none of these work  
Any idea on how to solve this without having to store the calculated field and also while keeping the standard foundset datasource?

---

<div class="post-metadata">

**Author:** ![rvanveen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rvanveen/32/4386_2.png) [@rvanveen](https://forum.servoy.com/u/rvanveen)\
**Post date:** [May 19, 2017, 9:24am UTC](https://forum.servoy.com/t/sorting-on-calculated-field/19261/2 "2017-05-19T09:24:05Z")

</div>

Hi,

The sort based on a function should work, the only problem is that a sort only works with the following values to sort:  
(-1, 0, 1).

Maybe this will help you to get it working.

```auto
foundset.sort(function(a,b) {
     return i18n.getI18NMessage(a.origfield).localeCompare(i18n.getI18NMessage(b.origfield));}

```
