Вот пример использования дополнительных параметров в теге paginate. Foo и Bar - это два класса домена со свойством String «name». Я создал 50 из каждого в Bootstrap.groovy.
PageController.groovy:
class PageController {
def index = {
if (params.paginate == 'Foo') {
def fooPagination = [max: params.max, offset: params.offset]
session.fooPagination = fooPagination
} else if (params.paginate == 'Bar') {
def barPagination = [max: params.max, offset: params.offset]
session.barPagination = barPagination
}
def barList = Bar.list(session.barPagination ?: [max: 10, offset: 0])
def fooList = Foo.list(session.fooPagination ?: [max: 10, offset: 0])
//This is to stop the paginate using params.offset/max to calculate current step and use the offset/max attributes instead
params.offset = null
params.max = null
[fooList: fooList, totalFoos: Foo.count(), totalBars: Bar.count(), barList: barList]
}
}
index.gsp:
<html>
<head>
<title>Multi Pagination Example</title>
<meta name="layout" content="main"/>
<style type="text/css" media="screen">
h2 {
margin-top: 15px;
margin-bottom: 15px;
font-size: 1.2em;
}
</style>
</head>
<body>
<table>
<tr>
<td>
<h2>Foo</h2>
<table>
<tr>
<th>Name</th>
</tr>
<g:each in="${fooList}">
<tr><td>${it.name}</td></tr>
</g:each>
<tr>
<td class="paginateButtons">
<g:paginate total="${totalFoos}" max="10" offset="${session.fooPagination?.offset}" params="${[paginate:'Foo']}"/></td>
</tr>
</table>
</td>
<td>
<h2>Bar</h2>
<table>
<tr>
<th>Name</th>
</tr>
<g:each in="${barList}">
<tr><td>${it.name}</td></tr>
</g:each>
<tr>
<td class="paginateButtons">
<g:paginate total="${totalBars}" max="10" offset="${session.barPagination?.offset}" params="${[paginate:'Bar']}"/></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
веселит
Lee
Спасибо за ваш ответ. Я немного новый для грааля, и я до сих пор не получил работу, ни действием, ни идентификатором. Вы могли бы дать мне больше подробностей? – emiles
@emiles Я обновил свой ответ на примере – leebutts
Я внимательно следил за вашим примером, но я не вижу параметр «pagination» в моем действии контроллера. Есть ли причина, по которой атрибут params не будет включать пользовательское значение? Я должен также упомянуть, что я относительно новичок в вселенной grails ... – toddk