Telerik UI for Windows 8 HTML

To get a sorted data set from a table, use the sort(propertyName, direction) method. The method receives two arguments:

  • propertyName: The name of the field (table column) that you want to sort by.

  • direction: The sort order – "asc" for ascending or "desc" for descending.

To apply the sort expression, call the execute() method.

The following example shows how to apply a single sort expression to the data retrieved from a Sales table in a SalesDB database.

Apply Single Sort Expression Copy imageCopy
db.get("Sales")
    .sort("name", "asc")
    .execute().then(querySuccess);

The above example will produce the same result as calling the query method with the following SQL expression:

SQL Copy imageCopy
SELECT * FROM Sales ORDER BY name ASC

To apply multiple sort expressions, use the sort(propertyName, direction) method multiple times. At the end, call the execute() method to trigger the chain of sort expressions.

This example shows how to apply multiple sort expressions.

Apply Multiple Sort Expressions Copy imageCopy
db.get("Sales")
    .sort("salesQuota", "desc")
    .sort("name", "asc")
    .execute().then(querySuccess);

The above logic is equivalent to the following SQL expression:

SQL Copy imageCopy
SELECT * FROM Sales ORDER BY salesQuota DESC, name ASC

See Also