Wiki source code of Pagination
Version 23.1 by Manuel Smeria on 2013/02/18
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
23.1 | 1 | = Pagination = |
![]() |
1.1 | 2 | |
![]() |
23.1 | 3 | {{info}} |
4 | This was committed in 1.9RC1. See http://jira.xwiki.org/jira/browse/XWIKI-3880 for details. | ||
5 | {{/info}} | ||
![]() |
1.1 | 6 | |
![]() |
23.1 | 7 | {{toc start="2" depth="2" numbered=""/}} |
![]() |
2.1 | 8 | |
![]() |
23.1 | 9 | == Example == |
![]() |
2.1 | 10 | |
![]() |
23.1 | 11 | See [[http://incubator.myxwiki.org/xwiki/bin/view/Main/ListWebSearch]] |
![]() |
1.1 | 12 | |
![]() |
23.1 | 13 | == Upper navigation == |
![]() |
17.2 | 14 | |
![]() |
23.1 | 15 | [[image:Example-UpperNavigation.png||width="950"]] |
![]() |
3.1 | 16 | |
![]() |
23.1 | 17 | === CSS === |
18 | |||
![]() |
7.1 | 19 | Filters CSS: |
![]() |
23.1 | 20 | |
21 | {{code}} | ||
![]() |
4.1 | 22 | .searchFilters{ |
23 | clear: both; | ||
24 | font-size: 90%; | ||
25 | } | ||
26 | #sortFilter{ | ||
![]() |
17.10 | 27 | color: #888; |
![]() |
4.1 | 28 | padding: 5px; |
29 | line-height: 16px; | ||
30 | } | ||
31 | #sortFilter a.sortType{ | ||
![]() |
17.10 | 32 | color: #888; |
![]() |
4.1 | 33 | } |
34 | #sortFilter a.sortType:hover{ | ||
35 | color: #4D4D4D; | ||
36 | } | ||
37 | #sortFilter a#currentSort{ | ||
38 | color: #4D4D4D; | ||
39 | font-weight: bold; | ||
40 | } | ||
![]() |
5.1 | 41 | #sortFilter a.sortType:focus, |
42 | #sortFilter a#currentSort:focus { | ||
![]() |
4.1 | 43 | outline: dotted 1px #000; |
44 | } | ||
![]() |
23.1 | 45 | {{/code}} |
![]() |
1.1 | 46 | |
![]() |
7.1 | 47 | Pagination with number of result pages displayed: |
![]() |
23.1 | 48 | |
49 | {{code}} | ||
![]() |
4.1 | 50 | .paginationFilter { |
![]() |
17.10 | 51 | color: #888; |
![]() |
4.1 | 52 | height: 100%; |
53 | border-top: 1px solid #CCCCCC; | ||
54 | padding: 2px 0px 5px 5px; | ||
55 | display: block; | ||
56 | line-height: 22px; | ||
57 | } | ||
58 | .resultsNo{ | ||
59 | float: left; | ||
60 | } | ||
61 | .resultsNo .currentResultsNo, .resultsNo .totalResultsNo{ | ||
![]() |
17.10 | 62 | color: #888; |
![]() |
4.1 | 63 | } |
64 | .pagination{ | ||
65 | float: right; | ||
66 | margin-right: 10px; | ||
67 | } | ||
68 | .pagination a{ | ||
![]() |
17.10 | 69 | color: #888; |
![]() |
4.1 | 70 | } |
71 | .pagination a:hover{ | ||
72 | color: #4D4D4D; | ||
73 | } | ||
74 | .pagination a.currentPagination{ | ||
75 | color: #4D4D4D; | ||
76 | font-weight: bold; | ||
77 | } | ||
78 | .pagination a:focus { | ||
79 | outline: dotted 1px #000; | ||
80 | } | ||
81 | .controlPagination{ | ||
82 | position:relative; | ||
83 | width:42px; | ||
84 | height:22px; | ||
85 | overflow:hidden; | ||
86 | margin:0!important; | ||
87 | padding:0!important; | ||
88 | float: right; | ||
89 | } | ||
90 | .controlPagination a{ | ||
91 | position:absolute; | ||
92 | top:0; | ||
93 | left:0; | ||
94 | line-height:25px; | ||
95 | outline:none; | ||
96 | overflow:hidden; | ||
97 | border:none; | ||
98 | } | ||
![]() |
17.12 | 99 | .controlPagination a.prevPagination , |
100 | .controlPagination a.noPrevPagination, | ||
101 | .controlPagination a.nextPagination, | ||
102 | .controlPagination a.noNextPagination { | ||
![]() |
4.1 | 103 | background-image:url($xwiki.getSkinFile("navigation.png")); |
104 | width: 21px; | ||
105 | height: 22px; | ||
106 | } | ||
![]() |
17.12 | 107 | .controlPagination a.prevPagination { |
108 | background-position:left top; | ||
109 | } | ||
![]() |
4.1 | 110 | .controlPagination a.noPrevPagination{ |
111 | background-position:left bottom; | ||
112 | } | ||
113 | .controlPagination a.nextPagination { | ||
114 | background-position:right top; | ||
115 | left: 21px; | ||
116 | } | ||
117 | .controlPagination a.noNextPagination { | ||
118 | background-position:right bottom; | ||
119 | left: 21px; | ||
![]() |
17.12 | 120 | } |
![]() |
23.1 | 121 | {{/code}} |
![]() |
4.1 | 122 | |
![]() |
23.1 | 123 | === HTML Code === |
![]() |
1.1 | 124 | |
![]() |
23.1 | 125 | {{code}} |
![]() |
3.1 | 126 | <div class="searchFilters"> |
![]() |
4.1 | 127 | |
![]() |
3.1 | 128 | <div id="sortFilter"> |
129 | $msg.get("xe.search.filters.sort") | ||
130 | <a href="" id="currentSort" title="$msg.get('xe.search.filters.relevance.title')">$msg.get("xe.search.filters.relevance")</a> | ||
131 | <a href="" class="sortType" title="$msg.get('xe.search.filters.date.title')">$msg.get("xe.search.filters.date")</a> | ||
132 | <a href="" class="sortType" title="$msg.get('xe.search.filters.rating.title')">$msg.get("xe.search.filters.rating")</a> | ||
133 | <a href="" class="sortType" title="$msg.get('xe.search.filters.popularity.title')">$msg.get("xe.search.filters.popularity")</a> | ||
134 | </div> | ||
135 | |||
136 | <div class="paginationFilter"> | ||
![]() |
4.1 | 137 | |
![]() |
18.1 | 138 | <span class="resultsNo">$msg.get("xe.pagination.results") <span class="currentResultsNo">6-30</span> $msg.get("xe.pagination.results.of") <span class="totalResultsNo">50</span></span> |
![]() |
4.1 | 139 | |
![]() |
3.1 | 140 | <span class="controlPagination"> |
![]() |
18.1 | 141 | <a href="#" title="$msg.get('xe.pagination.page.prev.title')" class="prevPagination"></a> |
142 | <a href="#" title="$msg.get('xe.pagination.page.next.title')" class="nextPagination"></a> | ||
![]() |
3.1 | 143 | </span> |
![]() |
18.1 | 144 | <span class="pagination">$msg.get("xe.pagination.page") |
145 | <a href="" title="$msg.get('xe.pagination.page.title',['1'])">1</a> | ||
146 | <a href="" class="currentPagination" title="$msg.get('xe.pagination.page.title',['2'])">2</a> | ||
147 | <a href="" title="$msg.get('xe.pagination.page.title',['3'])">3</a> | ||
148 | <a href="" title="$msg.get('xe.pagination.page.title',['4'])">4</a> | ||
149 | <a href="" title="$msg.get('xe.pagination.page.title',['5'])">5</a> | ||
150 | <a href="" title="$msg.get('xe.pagination.page.title',['6'])">6</a> | ||
151 | <a href="" title="$msg.get('xe.pagination.page.title',['7'])">7</a> | ||
152 | <a href="" title="$msg.get('xe.pagination.page.title',['8'])">8</a> | ||
153 | <a href="" title="$msg.get('xe.pagination.page.title',['9'])">9</a> | ||
![]() |
3.1 | 154 | </span> |
155 | </div> | ||
156 | </div> | ||
![]() |
23.1 | 157 | {{/code}} |
![]() |
3.1 | 158 | |
![]() |
23.1 | 159 | {{velocity filter="none"}} |
160 | {{html clean="false" wiki="true"}} | ||
161 | == <span id="bottomNav"> Bottom Navigation</span> == | ||
![]() |
3.1 | 162 | |
![]() |
23.1 | 163 | [[image:Example-BottomNavigation.png||width="950"]] |
164 | <p/> | ||
![]() |
7.1 | 165 | This is a lighter version of the Upper Navigation, keeping only the pagination controls. |
166 | |||
![]() |
23.1 | 167 | === CSS === |
![]() |
3.1 | 168 | |
![]() |
7.1 | 169 | Container: |
![]() |
23.1 | 170 | |
171 | {{code}} | ||
![]() |
4.1 | 172 | .paginationFooter{ |
173 | display: block; | ||
174 | clear: both; | ||
175 | text-align: right; | ||
176 | font-size: 90%; | ||
177 | } | ||
![]() |
23.1 | 178 | {{/code}} |
![]() |
3.1 | 179 | |
![]() |
17.12 | 180 | Same as in Upper navigation (don't apply if both navigations are present): |
![]() |
23.1 | 181 | |
182 | {{code}} | ||
![]() |
4.1 | 183 | .paginationFilter { |
![]() |
17.10 | 184 | color: #888; |
![]() |
4.1 | 185 | height: 100%; |
186 | border-top: 1px solid #CCCCCC; | ||
187 | padding: 2px 0px 5px 5px; | ||
188 | display: block; | ||
189 | line-height: 22px; | ||
190 | } | ||
191 | .pagination{ | ||
192 | float: right; | ||
193 | margin-right: 10px; | ||
194 | } | ||
195 | .pagination a{ | ||
![]() |
17.10 | 196 | color: #888; |
![]() |
4.1 | 197 | } |
198 | .pagination a:hover{ | ||
199 | color: #4D4D4D; | ||
200 | } | ||
201 | .pagination a.currentPagination{ | ||
202 | color: #4D4D4D; | ||
203 | font-weight: bold; | ||
204 | } | ||
205 | .pagination a:focus { | ||
206 | outline: dotted 1px #000; | ||
207 | } | ||
208 | .controlPagination{ | ||
209 | position:relative; | ||
210 | width:42px; | ||
211 | height:22px; | ||
212 | overflow:hidden; | ||
213 | margin:0!important; | ||
214 | padding:0!important; | ||
215 | float: right; | ||
216 | } | ||
217 | .controlPagination a{ | ||
218 | position:absolute; | ||
219 | top:0; | ||
220 | left:0; | ||
221 | line-height:25px; | ||
222 | outline:none; | ||
223 | overflow:hidden; | ||
224 | border:none; | ||
225 | } | ||
![]() |
17.12 | 226 | .controlPagination a.prevPagination , |
227 | .controlPagination a.noPrevPagination, | ||
228 | .controlPagination a.nextPagination, | ||
229 | .controlPagination a.noNextPagination { | ||
![]() |
4.1 | 230 | background-image:url($xwiki.getSkinFile("navigation.png")); |
231 | width: 21px; | ||
232 | height: 22px; | ||
233 | } | ||
![]() |
17.12 | 234 | .controlPagination a.prevPagination { |
235 | background-position:left top; | ||
236 | } | ||
![]() |
4.1 | 237 | .controlPagination a.noPrevPagination{ |
238 | background-position:left bottom; | ||
239 | } | ||
240 | .controlPagination a.nextPagination { | ||
241 | background-position:right top; | ||
242 | left: 21px; | ||
243 | } | ||
244 | .controlPagination a.noNextPagination { | ||
245 | background-position:right bottom; | ||
246 | left: 21px; | ||
![]() |
17.12 | 247 | } |
![]() |
23.1 | 248 | {{/code}} |
![]() |
4.1 | 249 | |
![]() |
23.1 | 250 | === HTML Code === |
![]() |
3.1 | 251 | |
![]() |
23.1 | 252 | {{code}} |
![]() |
4.1 | 253 | <div class="paginationFooter"> |
254 | <div class="paginationFilter"> | ||
255 | <span class="controlPagination"> | ||
![]() |
18.1 | 256 | <a href="#" title="$msg.get('xe.pagination.page.prev.title')" class="noPrevPagination"></a> |
257 | <a href="#" title="$msg.get('xe.pagination.page.next.title')" class="noNextPagination"></a> | ||
![]() |
4.1 | 258 | </span> |
259 | <span class="pagination"> | ||
![]() |
18.1 | 260 | $msg.get("xe.pagination.page") |
261 | <a href="" title="$msg.get('xe.pagination.page.title',['1'])">1</a> | ||
262 | <a href="" class="currentPagination" title="$msg.get('xe.pagination.page.title',['2'])">2</a> | ||
263 | <a href="" title="$msg.get('xe.pagination.page.title',['3'])">3</a> | ||
264 | <a href="" title="$msg.get('xe.pagination.page.title',['4'])">4</a> | ||
265 | <a href="" title="$msg.get('xe.pagination.page.title',['5'])">5</a> | ||
266 | <a href="" title="$msg.get('xe.pagination.page.title',['6'])">6</a> | ||
267 | <a href="" title="$msg.get('xe.pagination.page.title',['7'])">7</a> | ||
268 | <a href="" title="$msg.get('xe.pagination.page.title',['8'])">8</a> | ||
269 | <a href="" title="$msg.get('xe.pagination.page.title',['9'])">9</a> | ||
![]() |
4.1 | 270 | </span> |
271 | </div> | ||
272 | </div> | ||
![]() |
23.1 | 273 | {{/code}} |
![]() |
1.1 | 274 | |
![]() |
23.1 | 275 | == <span id="dependencies"> Dependencies</span> == |
![]() |
8.1 | 276 | |
![]() |
23.1 | 277 | === Icons === |
![]() |
8.1 | 278 | |
![]() |
17.4 | 279 | navigation.png |
![]() |
23.1 | 280 | <p/> |
281 | [[image:navigation.png]] | ||
![]() |
8.1 | 282 | |
![]() |
23.1 | 283 | === Translations === |
![]() |
17.4 | 284 | |
![]() |
23.1 | 285 | ==== Sort Translations ==== |
![]() |
8.1 | 286 | |
287 | xe.search.filters.sort=Sort: | ||
![]() |
23.1 | 288 | <p/> |
![]() |
8.1 | 289 | xe.search.filters.relevance=Relevance |
![]() |
23.1 | 290 | <p/> |
![]() |
8.1 | 291 | xe.search.filters.relevance.title=Sort by Relevance |
![]() |
23.1 | 292 | <p/> |
![]() |
8.1 | 293 | xe.search.filters.date=Date |
![]() |
23.1 | 294 | <p/> |
![]() |
8.1 | 295 | xe.search.filters.date.title=Sort by Date |
![]() |
23.1 | 296 | <p/> |
![]() |
8.1 | 297 | xe.search.filters.rating=Rating |
![]() |
23.1 | 298 | <p/> |
![]() |
8.1 | 299 | xe.search.filters.rating.title=Sort by Rating |
![]() |
23.1 | 300 | <p/> |
![]() |
8.1 | 301 | xe.search.filters.popularity=Popularity |
![]() |
23.1 | 302 | <p/> |
![]() |
8.1 | 303 | xe.search.filters.popularity.title=Sort by Popularity |
304 | |||
![]() |
23.1 | 305 | ==== Navigation Translations ==== |
![]() |
8.1 | 306 | |
![]() |
18.1 | 307 | xe.pagination.results=Results |
![]() |
23.1 | 308 | <p/> |
![]() |
18.1 | 309 | xe.pagination.results.of=out of |
![]() |
23.1 | 310 | <p/> |
![]() |
18.1 | 311 | xe.pagination.page=Page |
![]() |
23.1 | 312 | <p/> |
![]() |
18.1 | 313 | xe.pagination.page.title=Page {0} |
![]() |
23.1 | 314 | <p/> |
![]() |
18.1 | 315 | xe.pagination.page.prev.title=Previous Page |
![]() |
23.1 | 316 | <p/> |
![]() |
18.1 | 317 | xe.pagination.page.next.title=Next Page |
![]() |
8.1 | 318 | |
![]() |
23.1 | 319 | == Velocity Macro == |
![]() |
20.1 | 320 | |
![]() |
23.1 | 321 | {{code language="none"}}#pagination($parameters){{/code}} |
![]() |
20.1 | 322 | |
323 | The macro is responsible for displaying browsing links, and does not involve the actual display of the browsed items. | ||
![]() |
23.1 | 324 | <p/> |
![]() |
20.1 | 325 | It accepts a single argument, which in turn is a map of parameters: |
326 | <dl> | ||
327 | <dt>url</dt> | ||
328 | <dd>The base url of the document displaying the collection.</dd> | ||
![]() |
23.1 | 329 | <dd>Default: $doc.getURL('view')</dd> |
![]() |
20.1 | 330 | <dt>totalItems</dt> |
331 | <dd>The total number number of items in the collection.</dd> | ||
332 | <dd>Default: none, this parameter is mandatory.</dd> | ||
333 | <dt>defaultItemsPerPage</dt> | ||
334 | <dd>The number of items per page. This value is overwritten by the request parameter "perPage", if it exists and | ||
335 | has a valid positive integer value.</dd> | ||
336 | <dd>Default: 20</dd> | ||
337 | <dt>position</dt> | ||
338 | <dd>The placement of the pagination widget. Supported values: "top", "bottom". The bottom widget only displays | ||
339 | pages, while the top widget also provides a information about the item range on the current page.</dd> | ||
340 | <dd>Default: top</dd> | ||
341 | <dt>itemParamName</dt> | ||
342 | <dd>The name of the request parameter for the index of the first displayed item.</dd> | ||
343 | <dd>Default: firstIndex</dd> | ||
344 | <dt>itemsPerPageParamName</dt> | ||
345 | <dd>The name of the request parameter for the number of items displayed on a page.</dd> | ||
346 | <dd>Default: perPage</dd> | ||
347 | </dl> | ||
![]() |
23.1 | 348 | <p/> |
349 | Usage example: | ||
![]() |
20.1 | 350 | |
![]() |
23.1 | 351 | {{code language="none"}} |
![]() |
20.1 | 352 | #set($paginationParameters = { |
353 | 'url' : $doc.getURL('view', "text=${query}"), | ||
354 | 'totalItems' : $searchresults.getHitcount(), | ||
355 | 'defaultItemsPerPage' : $defaultItemsPerPage, | ||
356 | 'position': 'top' | ||
357 | }) | ||
358 | #pagination($paginationParameters) | ||
![]() |
23.1 | 359 | {{/code}} |
![]() |
21.1 | 360 | |
![]() |
23.1 | 361 | === Example === |
![]() |
21.1 | 362 | |
363 | The pagination macro can be used for example to display the latest modifications of the current user: | ||
364 | |||
![]() |
23.1 | 365 | {{code language="none"}} |
366 | #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true)) | ||
![]() |
21.1 | 367 | #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true)) |
368 | ## | ||
369 | ## set display parameters for the list | ||
370 | ## | ||
371 | #set($defaultItemsPerPage = 10) | ||
![]() |
22.1 | 372 | #set($orderClause = "order by doc.date desc") |
373 | #set($whereClause = "where 1=1 and doc.author='$context.user'") | ||
![]() |
21.1 | 374 | #set($results_url = $doc.getURL('view')) |
![]() |
22.1 | 375 | #set($totalItems = $xwiki.countDocuments($whereClause)) |
376 | #if($totalItems > 0) | ||
![]() |
21.1 | 377 | ## ----------------- |
378 | ## Pagination (top) | ||
379 | ## ----------------- | ||
![]() |
22.1 | 380 | #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) |
![]() |
21.1 | 381 | #pagination($paginationParameters) |
382 | ## ----------------- | ||
383 | ## Display results | ||
384 | ## ----------------- | ||
385 | #set($firstIndex = "$!{paginationParameters.firstItem}") | ||
386 | #if($firstIndex == '') | ||
387 | #set($firstIndex = "$!request.getParameter('firstIndex')") | ||
388 | #if($firstIndex == '') | ||
389 | #set($firstIndex = '0') | ||
390 | #end | ||
391 | #end | ||
392 | #set($firstIndex = $util.parseInt($firstIndex)) | ||
![]() |
22.1 | 393 | #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex)) |
![]() |
21.1 | 394 | #set ($list = $results) |
395 | #set ($isScored = false) | ||
396 | #includeInContext("XWiki.Results") | ||
397 | ## ----------------- | ||
398 | ## Pagination (bottom) | ||
399 | ## ----------------- | ||
400 | #set($paginationParameters.position = 'bottom') | ||
401 | #pagination($paginationParameters) | ||
402 | #end | ||
![]() |
23.1 | 403 | {{/code}} |
![]() |
21.1 | 404 | |
405 | #if(!$isGuest) | ||
![]() |
22.1 | 406 | #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true)) |
407 | #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true)) | ||
![]() |
21.1 | 408 | ## |
409 | ## set display parameters for the list | ||
410 | ## | ||
411 | #set($defaultItemsPerPage = 10) | ||
![]() |
22.1 | 412 | #set($orderClause = "order by doc.date desc") |
413 | #set($whereClause = "where 1=1 and doc.author='$context.user'") | ||
![]() |
21.1 | 414 | #set($results_url = $doc.getURL('view')) |
![]() |
22.1 | 415 | #set($totalItems = $xwiki.countDocuments($whereClause)) |
416 | #if($totalItems > 0) | ||
![]() |
21.1 | 417 | ## ----------------- |
418 | ## Pagination (top) | ||
419 | ## ----------------- | ||
![]() |
22.1 | 420 | #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) |
![]() |
21.1 | 421 | #pagination($paginationParameters) |
422 | ## ----------------- | ||
423 | ## Display results | ||
424 | ## ----------------- | ||
425 | #set($firstIndex = "$!{paginationParameters.firstItem}") | ||
426 | #if($firstIndex == '') | ||
427 | #set($firstIndex = "$!request.getParameter('firstIndex')") | ||
428 | #if($firstIndex == '') | ||
429 | #set($firstIndex = '0') | ||
430 | #end | ||
431 | #end | ||
432 | #set($firstIndex = $util.parseInt($firstIndex)) | ||
![]() |
22.1 | 433 | #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex)) |
![]() |
21.1 | 434 | #set ($list = $results) |
435 | #set ($isScored = false) | ||
![]() |
23.1 | 436 | {{include document="XWiki.Results"/}} |
![]() |
21.1 | 437 | ## ----------------- |
438 | ## Pagination (bottom) | ||
439 | ## ----------------- | ||
440 | #set($paginationParameters.position = 'bottom') | ||
441 | #pagination($paginationParameters) | ||
442 | #end | ||
443 | #end | ||
![]() |
22.1 | 444 | |
![]() |
23.1 | 445 | {{/html}} |
446 | {{/velocity}} |