:: Forum >> Version 2 >>

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
Monday, February 6, 2006
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(valuesgreaterlessequalerror){
    return function(
ij){
        
try {
            var 
values[i];
            var 
values[j];
            if (
b) {return greater}
            if (
b) {return less}
            return 
equal(ij);
        }
        
catch(e){
            return 
error(ije);
        }
    }
};
 
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)
Monday, February 6, 2006
thanks, overriding the comapator in a custom class worked fine
Jonathan Doklovic
Monday, February 6, 2006



This topic is archived.

Back to support forum

Forum search