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.

Regards
Servoy Developer
dev-ws-011
 
Posts: 73
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

Hi,

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 Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1742
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 7 guests