2015-04-04 53 views
0

在索引方法中,我列出了特定播放器的记录。如何在Grails视图中对列进行排序

例如

def index() { 
    Player player = Player.get(params.playerId) 
    def records = Record.findAllByPlayer(player, params:params) 

    [records: records, playerInstance: player, params: params] 
} 

这是有效的,但没有可排序的列在视图中工作。

如何查找我需要排序的列以及如何在findAllByXXX中使用此信息?我搜索了谷歌,但没有找到任何不涉及简单的“Books.list(params)”模式的例子。

在视图中,我有sortableColumns:

<g:sortableColumn property="createdAt" title="${message(code: 'paymentRecord.created.label', default: 'Created at')} " 
        params="${params}" style="width: 15%;"/> 

,我看到的参数在网址的结尾,例如:

/index/1?sort=credit&order=desc 

回答

2

分页和排序,其可在list方法也可以与动态查找器中使用的参数。

所以你可以这样做,如果你有排序和顺序可用params。

Record.findAllByPlayer(player, params) 

或者

Record.findAllByPlayer(player, [max: xx, offset: xx, sort: "name", order: "desc"]) 
2

你需要做Record.findAllByPlayer(player, params)而不是Record.findAllByPlayer(player, params:params)

您可以看到示例here in grails documentation。从文档的一个例子是

def results = Book.findAllByTitle("The Shining", 
       [max: 10, sort: "title", order: "desc", offset: 100]) 
相关问题