简体   繁体   English

如何在Grails分页期间保留搜索关键字?

[英]How to retain a search keyword during Grails pagination?

I have a simple Grails application. 我有一个简单的Grails应用程序。 It has search form with one textfield and one submit button. 它具有带有一个文本字段和一个提交按钮的搜索表单。 If the results exceed the total number of 100, then Grails pagination appears and if I click on the second page's link, the call goes to the same controller's method, however, the search keyword is not passed this time (because the pagination is not the part of the search form) and it is not there in 'params'. 如果结果超过总数100,则出现Grails分页,并且如果我单击第二页的链接,则调用转到相同控制器的方法,但是,这次没有通过search关键字(因为分页不是搜索表单的一部分),并且它不在“ params”中。 How to handle this situation? 如何处理这种情况?

您可以使用pageScope.variables将所有参数传递给控制器​​,例如

<g:paginate params="${pageScope.variables}" total=.../>

If the name of your input field for search is say q , then you can do something like this: 如果您要搜索的输入字段的名称为q ,则可以执行以下操作:

 <g:paginate controller="user" action="index" total="${total}" q="params.q"/>

This will retain your search keyword on to your paginated pages. 这会将您的搜索关键字保留在分页上。

You can send parameters in the paginate tag 您可以在分页标签中发送参数

<g:paginate next="Forward" prev="Back"
        maxsteps="0" controller="book"
        action="list" total="${bookCount}"
        params="${[q:q, anotherParamether:anotherParamether]}" />

Paginate documentation 分页文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM