Quantcast

How do I use datatable paging and sorting in a view template?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How do I use datatable paging and sorting in a view template?

Mike Sickler
I've posted this here: http://stackoverflow.com/questions/1689796/grails-problem-with-paging-and-ordering-in-a-view-template but thought I would try the mailing list, too. 

-----------------

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.


Thanks,
Mike


Loading...