DataGrid.compare

Syntax

compare(value1, value2);

Parameters

value1. First compared value.

value2. Second compared value.

Description

The compare method compares two values.

Comments

The method returns 1 if the first value is greater than the second one, -1 if the second value is greater the the first one, 0 is both values are equal.

Example

To execute the example, the HTML page must contain the DataGrid component named grid (see Example of Creating the DataGrid Component). Compare two values and display the result:

// Compare two number values and display the result
var result = grid.compare(20, 10);
if (result == 1) {
    console.log("The first value is greater than the second one");
} else if (result == -1) {
    console.log("The second value is greater than the first one");
} else {
    console.log("Values are equal");
}

As a result the console displays check result:

The first value is greater than the second one

 

Compare two values and display the result:

// Compare two number values in the direct order and display the result
var result = grid.sortAsc(30, 30);
if (result == 1) {
    console.log("The first value is greater than the second one");
} else if (result == -1) {
    console.log("The second value is greater than the first one");
} else {
    console.log("Values are equal");
}

As a result the console displays check result:

Values are equal

 

Compare two values in the reverse order and display the result:

// Compare two number values in the reverse order and display the result
var result = grid.sortDesc(30, 50);
if (result == -1) {
    console.log("The first value is greater than the second one");
} else if (result == 1) {
    console.log("The second value is greater than the first one");
} else {
    console.log("Values are equal");
}

As a result the console displays check result:

The second value is greater than the first one

See also:

DataGrid