I have the following query which id like to sorty by "raceDate" and by "raceNo" asc. I can figure out how to sort by one field, but not by two, any ideas?
def list = {
params.max = Math.min( params.max ? params.max.toInteger() : 20, 100)
params.offset = params?.offset?.toInteger() ?: 0
params.sort = "raceDate"
params.order = params?.order ?: "asc"
def results = Race.createCriteria().list(
max: params.max,
offset: params.offset,
sort: params.sort,
order: params.order
) {
and {
if (params.raceNo && params.raceNo != '')
eq("raceNo", params.raceNo.toInteger())
if (params.country && params.country != '')
eq("country", params.country)
if (params.venue && params.venue != '')
eq("venue", params.venue)
if (params.raceType && params.raceType != '')
eq("raceType", params.raceType)
if (params.surface && params.surface != '')
eq("surface", params.surface)
if (params.officialGoing && params.officialGoing != '')
eq("officialGoing", params.officialGoing)
if (params.raceDateStart_year && params.raceDateStart_month && params.raceDateStart_day
&& params.raceDateEnd_year && params.raceDateEnd_month && params.raceDateEnd_day) {
String startInput = "${params.raceDateStart_year}/${params.raceDateStart_month}/${params.raceDateStart_day}"
Date startDate = jodaFormatter.parseDateTime(startInput).toDate();
String endInput = "${params.raceDateEnd_year}/${params.raceDateEnd_month}/${params.raceDateEnd_day}"
Date endDate = jodaFormatter.parseDateTime(endInput).toDate();
between("raceDate", startDate, endDate)
}
}
}
[ raceInstanceList:results, raceInstanceTotal:results.totalCount, params:params ]
}
Something like this should work:
def results = Race.createCriteria().list(
max: params.max,
offset: params.offset,
sort: params.sort,
) {
order('raceDate', 'asc')
order('raceNo', 'asc')
and {
if (params.raceNo && params.raceNo != '')
eq("raceNo", params.raceNo.toInteger())
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With