I retrieve rows on the my database through my domain using a code similar to this:
def DomainList = DomainClass.list(sort: orderBy, order: "asc")
Assuming that the orderBy variable is a String that is the name of one of the domain's column. But what if I want to sort it by a column index instead:
SELECT * FROM `table` ORDER BY 2 DESC
How can I do that on Grails?
After some time, I gave up on finding a dynamic solution. Instead, I use an
if-elsetrap at the beginning of the code since each index corresponds to a particular column:Note though, this is not dynamic. It cannot accommodate adding on new columns to the
DomainClass; you must manually edit also theif-elsetrap.