:: Documentation >>

comparator

Returns comparator function.

null

Syntax

var cmp = format.comparator(values, greater, less, equal, error);

Parameters

values (array) - array of values to compare
greater (number) - +1 or -1 depending on the sort direction
less (number) - -1 or +1 depending on the sort direction
equal (function) - to be callled if the values are equal
error (function) - to be called if there is an error

Returns

comparator function to be used in array.sort(function)

Examples

format.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);
        }
    }
};

See also

Grid control: sort method

Comments

Sort separation of numbers and strings in a column Anthony (4)

Documentation:

Recent changes:

2.6.4
2.6.3
2.6.2
2.6.1
2.6.1
2.6.0
2.5.0 - 2.5.6
2.5.6
2.5.0 - 2.5.5
2.5.5