tags:

views:

290

answers:

1

How do I structure my pages and partial templates so that Ajax will play nice with <paginate> and column sorting?

I currently have a search.gsp page with a remoteField that calls a controller to update a template. This all works fine. However, the column sorting and paging actions cause my search.gsp to be completely replaced by the template view.

From my search.gsp:

<div id="searchBox">
  Enter a key or phrase: <g:remoteField  name="searchBox"  
                         update="resourceSearchResultPanel" paramName="q"                                            
                         url="[controller:'resourceEntry',action:'searchForResources']" 
                         />
</div>
<div id="resourceSearchResultPanel" />

My controller handles the search request like so:

def searchForResources = {
        params.max = Math.min(params.max ? params.max.toInteger() : 10, 100)
        params.offset = params.offset ? params.offset.toInteger() : 0
        log.debug "Handling search post action"
        def q = params.q ?: null
        log.debug "Search phrase is $q"
        def searchResults
        if (q) {
            searchResults = [
                results: ResourceEntry.search(q,[offset: params.offset, max: params.max]),
                resultCount: ResourceEntry.countHits(q),
                q: q.encodeAsHTML()
            ]
        }
        render(template:"resourceSearchResultPanel",model:searchResults)
    }

The _resourceSearchResultPanel.gsp is just a table with this <paginate> tag:

<g:paginate action="searchForResources" total="${resultCount}" params='["q":"${q}"]'  />

The problem is that when the <paginate> tag calls the controller, the entire page is refreshed with the contents of the _resourceSearchResultPanel.gsp template, while I just want the _resourceSearchResultPanel.gsp itself to be refreshed inside search.gsp.

There's no update attribute like there is in the remoteField tag...

+1  A: 

The paginate tag doesn't support generating ajax links so you'll have to write your own verison of the tag that calls remoteLink instead of link.

cheers

Lee

leebutts
Am I better off trying to write my own, or should I look at using a different data table?
Mike Sickler
Thanks for the direction. A quick Google search for 'paginate remoteLink' brought me to someone who has implemented just that: http://tdsystemsgroup.com/resources.html
Mike Sickler