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
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
Hi,
this is not new in NG, it has been this way forever.
There are ways to get around this:
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.
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:
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.