Search code examples
grailspaginationcontrollergsp

Paginate Grails Table in GSP (complete list available)


Is there a way to paginate a complete list already available in grails?

I have a custom search something like that in my controller:

def updateSearchResults(String arg1, String arg2) {
    return filteredList
}

This is called with a remoteForm submitting the two arguments. an div is updated with the returned list (it is in a separate .gsp called updateSearchResults.gsp) works fine.

The issue is: this call returns between 5-100 results depending on the args (over 100 it will not display but show a warning to refine the search for less results - performance reason).

This means that I have at max 100 items to display in a table: Pagination needed!

I thought about implementing the pagination directly in the controller call - but I stumbled over the fact that it is a remoteformcall loading the list & I do not have the arguments available on the pagination buttons - so a change in page would result in a complete reload with no search arguments.

So the question is: how can I paginate a completely available list directly in my gsp?

I tried around but found no solution so far.


Solution

  • Since you have all the data already, you would want to paginate using javascript. Other than that, my suggestion is NOT to send all the data at once but to use an ajax call to grab the data you need with each pagination.