Sorting on calculated field

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Sorting on calculated field

Postby developers10 » Fri May 19, 2017 10:37 am

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
Code: Select all
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 :
Code: Select all
foundset.sort(calculated_field asc)

and also
Code: Select all
controller.sort(calculated_field asc)

Code: Select all
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?
developers10
 
Posts: 26
Joined: Thu Feb 23, 2017 5:33 pm

Re: Sorting on calculated field

Postby rvanveen » Fri May 19, 2017 11:24 am

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.

Code: Select all
foundset.sort(function(a,b) {
     return i18n.getI18NMessage(a.origfield).localeCompare(i18n.getI18NMessage(b.origfield));}
User avatar
rvanveen
 
Posts: 4
Joined: Fri Jul 01, 2016 10:51 am


Return to Programming with Servoy

Who is online

Users browsing this forum: Google [Bot] and 1 guest