Grails Pagination -
hello im tedious question!
trying table paginate. there 12 users in table. here controller function
def listduplicates(params) { def result = user.getallwithduplicateids() def totaldupcount = result.size() /*sout troubleshooting */ system.out.println("duplicate:" + result.id + " " + result.username) params.max = math.min(params.max ? params.int('max') : 10, 100) return [resultlist: result, totaldupcount: totaldupcount, params:params ] }
here view
<div> <fieldset class="warningfieldset"> <h1 style="color: red" align="center"> <g:message code="duplicate ids" /> </h1> <p style="color: red; margin-left: 20px;">duplicate ids found!</p> <table> <thead> <tr> <g:sortablecolumn property="username" title="username" /> <g:sortablecolumn property="id" title="id" /> <g:sortablecolumn property="status" title="status" /> </tr> </thead> <tbody> <g:each in="${resultlist}" status="i" var="resultduplicate"> <tr class="${(i % 2) == 0 ? 'even' : 'odd'}"> <td> ${resultduplicate.username} </td> <td style="color: red; font-weight: bold"> ${resultduplicate.id} </td> <td> ${resultduplicate.accountstatus } </tr> </g:each> </tbody> <tfoot> <g:if test="${totaldupcount >10 }"> <div class="paginatebuttons"> <g:paginate action= "listduplicates" total="${totaldupcount}" /> </div> </g:if> </tfoot> </table> </fieldset> </div>
domain function finding duplicate ids
static list<user> getallwithduplicateids() { findall("from user id in (select id user group id having count(*) > 1) , id != '' ", []) }
the buttons show up. , in url offset , max displayed. table puts 12 displayed instead of 10 on 1 page , 2 on other. 2 page numbers show knows suppose display 10 per page. isn't doing in table itself. im assuming kind of issue passing params , such.
any suggestions/opinions/help are/is appreciated!
grails pagination based on 2 parameters: max
, offset
. max
determines page size, , offset
determines current page starts. controller receives these parameters , passes them database query. list
method added domain objects grails handles these parameters, , finder methods take queryparams
. usual pattern pass params
object directly list
or queryparams
parameter finders. returns result set starting @ given offset, 1 page length.
in example, you're calling getallwithduplicateids
without making use of these parameters. update query take them, this:
static list<user> getallwithduplicateids(params) { findall("from user id in (select id user group id having count(*) > 1) , id != '' ", [], params) }
alternatively, page in memory like
results = results.drop(params.offset).take(params.max)
paging directly in query preferable, since perform better handle cases entire list doesn't fit in memory.
Comments
Post a Comment