Sorts a query.

querySort(query, sortFunction) → returns boolean

Member Function Syntax


querySort Argument Reference

query query

The query you want to sort

sortFunction function

CF 2016+ or Lucee 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 string

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



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

Examples sample code invoking the querySort function

//build a query
news = queryNew("id,title",
    [ {"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

Fork me on GitHub