querySort

Sorts a query.

querySort(query, sortFunction) → returns boolean

Member Function Syntax

query.sort(sortFunction)

querySort Argument Reference

query
Required

The query you want to sort

sortFunction
Required

CF 2016+ or Lucee 5.1.0.13+ a function with two arguments each corresponding to a query row. The function returns -1 if first row is less than second, 0 if equal, or 1 if first row is greater than second. Lucee 4.5+ accepts a column name to sort by instead of a function.

direction

Lucee 4.5+ Only supported on Lucee when second argument is a column name instead of a callback function.

Compatibility

Lucee:

Lucee also supports querySort(query, column_name [, direction]) syntax. As of 5.1.0.13 it accepts a callback function. When called as a member function query.sort() is chainable.

Examples sample code invoking the querySort function


Sorting a query using sort member function

//build a query
news = queryNew("id,title",
    "integer,varchar",
    [ {"id":1,"title":"Dewey defeats Truman"}, {"id":2,"title":"Man walks on Moon"} ]);
//sort it
news.sort(function(rowA, rowB) { return compare(rowA.title, rowB.title); });
//dump it
writeDump(news);

Fork me on GitHub