As I was looking today for a way to resort an existing query in my application, I though of the following options I had.
- Do a new call to SQL
- Create a QoQ and resort
Even though both options would work, I was unhappy with them. #1 because it is an additional call to the DB and #2 because I did not want to break out of my cfscript block. So I did a little googling and came up with the following post:
Check out the 2nd post. Basically you can apply the underlying Java sort function to your query Object and it will sort it for you, Like so;
As per the original author of this hint:
The findColumn() call is needed to get the index of the sort column, because sort() is working with the column indexes and not with the column names. The second parameter specifies the sort order: TRUE = ascending, FALSE = descending.
- Advantages: one-line call, faster than QoQ
- Disadvantage: sort restricted to one column
There are much more hidden features of the underlying Java class. See the following links for more information:
I just wanted to add for all my ColdBox Friends or Newbies, remember we have a handy plugin available for us that does this and a bit more...