:: Home >>

comparator

Returns comparator function.

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

No comments yet.
Comments will appear on this page and in the main forum.

Documentation:

Recent changes:

2.5.0 - 2.5.2
2.5.2
2.5, 2.5.1
2.5.1
2.5
Release History
2.5
2.0.2
textToValue
textToData