3.2.0

odd number format sorting

I have some data that has in invoice number that looks like:
10-195,265-195,360-105

when i sort this column, i want it to sort before the dash first and then after, so ascending would be:
10-195,265-195,360-105
descending would be:
360-105,265-195,10-195

anyone know how to do this?
can i set a custom sort function to a column or something?
Jonathan Doklovic
February 6,
You can create a custom format object and overwrite comparator() method. The comparator method returns function which is used in array sorting procedure. Here is the default implementation (/lib/system/format.js)

obj.comparator = function(values, greater, less, equal, error){
    return function(i, j){
        try {
            var a = values[i];
            var b = values[j];
            if (a > b) {return greater}
            if (a < b) {return less}
            return equal(i, j);
        }
        catch(e){
            return error(i, j, e);
        }
    }
};


Another example using String.localeCompare() is in /lib/formats/string.js

Alternatively you can overwrite dataToValue() method (comparison is made using values, not text or data).
Alex (ActiveWidgets)
February 6,
thanks, overriding the comapator in a custom class worked fine
Jonathan Doklovic
February 6,

This topic is archived.

See also:


Back to support forum