我只是从grails开始,想按降序对列表进行排序。我尝试了这个:
<g:sortableColumn property="eventStartDate" defaultOrder="asc" title="${message(code: 'event.eventStartDate.label', default: 'Event Start Date')}" />
但是,这不会对列表进行排序。 Controller 如下所示:
def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[eventInstanceList: Event.list(params), eventInstanceTotal: Event.count()]
}
如何按降序的eventStartDate排序?
最佳答案
它可能不起作用的原因是:
解决方案:
将 Controller 操作的第二行更改为:
[eventInstanceList: Event.list(order: "desc"), eventInstanceTotal: Event.count()]
更多信息:
http://grails.github.io/grails-doc/2.2.1/ref/Domain%20Classes/list.html
Event.list(params)
返回域对象中的所有内容。它不做任何过滤。请改用findAllBy*
或findBy*
或createCriteria
。例:
Event.findAllByNameAndDate(params.get("name"), params.get("date"), [max: 10, order: "desc"])
更多信息:
grails domain class .list() method with params
关于sorting - 如何在grails列表中排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34036030/