Search code examples
grailsgrails-controller

Grails controller/view list pagination not showing next/prev option


I am having problems with the next/prev options not displaying on lists with a Groovy on Grails site. I have modified the automatically generated controller code to limit the items in the list to be items that were created by the user. This works fine, however, if the user has more than 10 items, the next/prev buttons don't show up as expected. Below are the relevant code snippits...

Controller:

def list = {
   params.max = Math.min(params.max ? params.int('max') : 10, 100)
   def login = authenticationService.getSessionUser().getLogin()
   def authUser = AuthenticationUser.findByLogin(login)
   def userAcct = User.findByLoginID(authUser)
   def userServices = Service.createCriteria()
   def results
   if (userAcct.role == 'admin') {
      results = userServices.list(params) {}
   } else {
      results = userServices.list(params) {
         eq("userID", userAcct)
      }
   }
   [serviceInstanceList: results, serviceInstanceTotal: results.count()]
}

GSP:

        <div class="paginateButtons">
            <g:paginate total="${serviceInstanceTotal}" />
        </div>

When I log in with an account with the "admin' role, the next/prev links appear fine. Non-admin accounts do not display the next/prev links when there are more than 10 items to be listed. Can anyone see what I'm doing wrong?


Solution

  • Your criteria should give you a pagedResultList which has a totalCount. So try to change the last line of your controller to:

    [serviceInstanceList: results, serviceInstanceTotal: results.totalCount]