QuerySort

Sorts the query based on the column specified and the order criteria given. Modifies the original query object

QuerySort( query, columnNameOrSortFunc [, direction ] )

Returns: Boolean

Argument Description Default
query
query, required

the query to sort

columnNameOrSortFunc
any, required

a list of names, a single column name or a function used as comparator.

Alias: column_name, columnnames, columnname, name, names, column_names, sort, function, udf, sortFunction, sortFunc

direction
string, optional

a list of directions or a single direction definition (asc,desc), the list must have the same length as the columnName list

Alias: directions, dir

Examples

people = QueryNew( "name,dob,age", "varchar,date,int", [
    [ "Susi", CreateDate( 1970, 1, 1 ), 0 ],
    [ "Urs" , CreateDate( 1995, 1, 1 ), 0 ],
    [ "Fred", CreateDate( 1960, 1, 1 ), 0 ],
    [ "Jim" , CreateDate( 1988, 1, 1 ), 0 ]
]);
Dump( var=people, label="people - origional query" );
/* Output:
| name | dob                 | age |
------------------------------------
| Susi | 1970-01-01 00:00:00 | 0   |
| Urs  | 1995-01-01 00:00:00 | 0   |
| Fred | 1960-01-01 00:00:00 | 0   |
| Jim  | 1988-01-01 00:00:00 | 0   |
*/
people.sort('name', 'asc');
dump(var=people, label='people - sorted by name');
/* Output:
| name | dob                 | age |
------------------------------------
| Fred | 1960-01-01 00:00:00 | 0   |
| Jim  | 1988-01-01 00:00:00 | 0   |
| Susi | 1970-01-01 00:00:00 | 0   |
| Urs  | 1995-01-01 00:00:00 | 0   |
*/

See also