How to use Grails Page Section

I am new to grails and I tried using the grail pagination Tag found in grails documentation, I have a search form in my index.gsp

I don't know how to pass params.max and params.offset I use only one action index

I have an index action containing a query to list some books:

params.max = 10
params.offset = 0
def author=params.author // i get the input search params
def max = 10
def offset = 0
if(params.max){
    max = params.max
}
if(params.offset){
    offset = params.offset
}

def bookPagin=Book.createCriteria().list {      
    eq("author", author)}
    maxResults(max)
    firstResult(offset )
}

this is the paginate tag in my index.gsp:

 <g:paginate controller="displayBook" action="index" total="${bookPagin.size()}" params="[author:author]"/>

now this code displays the first 10 results, but when I click on the second page it does not accept the parameters of the input author, although I try to change the author parameter in the GET request, is there any other solution?

+4
source share
2 answers

Here's how I do it ...

def searchString = "${params.author}%"
def searchResults = Book.findAllByAuthorLike(searchString, params) // max, offset automatically handled
def total = Book.countByAuthorLike(searchString)
render (model:[searchResults: searchResults, total: total])

GSP, searchResults

<g:each var="book" in="${searchResults}">...

:

 <g:paginate controller="displayBook" action="index" total="${total}"/>
+4

Source: https://habr.com/ru/post/1535704/


All Articles