Sorting in NG Grid on Calculated Columns

Forum to discuss the new web client version of Servoy.

Sorting in NG Grid on Calculated Columns

Postby dev-ws-011 » Wed May 05, 2021 10:15 am

Hi All,

We are working with Servoy ver 2020.12. When we try to sort on columns in NG Grid which are bound to 'calculated field', sorting is not working.

Any help will be highly appreciated.

Servoy Developer
Posts: 66
Joined: Fri Oct 21, 2016 8:23 am

Re: Sorting in NG Grid on Calculated Columns

Postby mboegem » Sun May 09, 2021 5:40 pm


this is not new in NG, it has been this way forever.
There are ways to get around this:

1) just create a column with the exact same name as the calculated field, this wil make the calculated field a 'stored calculated field' and sorting will work.
Servoy will make sure that the value that is stored in the database is updated when the calculated value changes.

2) catch the sorting event and write your own logic to sort the foundset. The foundset.sort() function allows to pass in a function that will take 2 records that are to be compared as parameters.
Something like this:
Code: Select all
function customSort(_rec1, _rec2) {
    var _nResult = 0,
        _val1 = _rec1[calc_field];
        _val2 = _rec2[calc_field];
    if(_val1 < _val2) {
        _nResult = -1;
    } else if(_val1 > _val2) {
        _nResult = 1;
    return _nResult;   

It all depends on the content of your calc_field how this will hit performance.
For sure when the calc_field is using relations, this will be an expensive operation as you will see a lot of back-end queries being executed.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

User avatar
Posts: 1574
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 5 guests