Data retrieval with Sorting¶
Data retrieval and search API can request the server to return sorted data. Data can be sorted by one or more columns. The sorting direction can be either ascending (default) or descending for each individual column. JavaScript applications must use the Backendless.DataQueryBuilder
class to set the sorting option. The example below configures DataQueryBuilder
to sort results by the name
and age
columns. Value in the age
column are sorted in the descending order. The query is used to retrieve objects from the Person
table:
var queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setSortBy( ["name", "age DESC" ] );
Backendless.Data.of( "Person" ).find( queryBuilder )
.then( function( result ) {
// the "result" object is an array of plain JS objects.
// each item in the array represents an object from the "Person" table
})
.catch( function( error ) {
// use the .statusCode or .message on the "error" object
// to see the details of the error
});
var queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setSortBy( ["name", "age DESC"] );
Backendless.Data.of( Person ).find( queryBuilder )
.then( function( result ) {
// the "result" object is an array of Person objects.
// each item in the array represents an object from the "Person" table
})
.catch( function( error ) {
// use the .statusCode or .message on the "error" object
// to see the details of the error
});
Important
The descending sorting order can be requested by adding DESC to the name of the column (separated by space).