Wiki source code of Pagination
Version 23.1 by Manuel Smeria on 2013/02/18
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | = Pagination = | ||
2 | |||
3 | {{info}} | ||
4 | This was committed in 1.9RC1. See http://jira.xwiki.org/jira/browse/XWIKI-3880 for details. | ||
5 | {{/info}} | ||
6 | |||
7 | {{toc start="2" depth="2" numbered=""/}} | ||
8 | |||
9 | == Example == | ||
10 | |||
11 | See [[http://incubator.myxwiki.org/xwiki/bin/view/Main/ListWebSearch]] | ||
12 | |||
13 | == Upper navigation == | ||
14 | |||
15 | [[image:Example-UpperNavigation.png||width="950"]] | ||
16 | |||
17 | === CSS === | ||
18 | |||
19 | Filters CSS: | ||
20 | |||
21 | {{code}} | ||
22 | .searchFilters{ | ||
23 | clear: both; | ||
24 | font-size: 90%; | ||
25 | } | ||
26 | #sortFilter{ | ||
27 | color: #888; | ||
28 | padding: 5px; | ||
29 | line-height: 16px; | ||
30 | } | ||
31 | #sortFilter a.sortType{ | ||
32 | color: #888; | ||
33 | } | ||
34 | #sortFilter a.sortType:hover{ | ||
35 | color: #4D4D4D; | ||
36 | } | ||
37 | #sortFilter a#currentSort{ | ||
38 | color: #4D4D4D; | ||
39 | font-weight: bold; | ||
40 | } | ||
41 | #sortFilter a.sortType:focus, | ||
42 | #sortFilter a#currentSort:focus { | ||
43 | outline: dotted 1px #000; | ||
44 | } | ||
45 | {{/code}} | ||
46 | |||
47 | Pagination with number of result pages displayed: | ||
48 | |||
49 | {{code}} | ||
50 | .paginationFilter { | ||
51 | color: #888; | ||
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{ | ||
62 | color: #888; | ||
63 | } | ||
64 | .pagination{ | ||
65 | float: right; | ||
66 | margin-right: 10px; | ||
67 | } | ||
68 | .pagination a{ | ||
69 | color: #888; | ||
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 | } | ||
99 | .controlPagination a.prevPagination , | ||
100 | .controlPagination a.noPrevPagination, | ||
101 | .controlPagination a.nextPagination, | ||
102 | .controlPagination a.noNextPagination { | ||
103 | background-image:url($xwiki.getSkinFile("navigation.png")); | ||
104 | width: 21px; | ||
105 | height: 22px; | ||
106 | } | ||
107 | .controlPagination a.prevPagination { | ||
108 | background-position:left top; | ||
109 | } | ||
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; | ||
120 | } | ||
121 | {{/code}} | ||
122 | |||
123 | === HTML Code === | ||
124 | |||
125 | {{code}} | ||
126 | <div class="searchFilters"> | ||
127 | |||
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"> | ||
137 | |||
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> | ||
139 | |||
140 | <span class="controlPagination"> | ||
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> | ||
143 | </span> | ||
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> | ||
154 | </span> | ||
155 | </div> | ||
156 | </div> | ||
157 | {{/code}} | ||
158 | |||
159 | {{velocity filter="none"}} | ||
160 | {{html clean="false" wiki="true"}} | ||
161 | == <span id="bottomNav"> Bottom Navigation</span> == | ||
162 | |||
163 | [[image:Example-BottomNavigation.png||width="950"]] | ||
164 | <p/> | ||
165 | This is a lighter version of the Upper Navigation, keeping only the pagination controls. | ||
166 | |||
167 | === CSS === | ||
168 | |||
169 | Container: | ||
170 | |||
171 | {{code}} | ||
172 | .paginationFooter{ | ||
173 | display: block; | ||
174 | clear: both; | ||
175 | text-align: right; | ||
176 | font-size: 90%; | ||
177 | } | ||
178 | {{/code}} | ||
179 | |||
180 | Same as in Upper navigation (don't apply if both navigations are present): | ||
181 | |||
182 | {{code}} | ||
183 | .paginationFilter { | ||
184 | color: #888; | ||
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{ | ||
196 | color: #888; | ||
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 | } | ||
226 | .controlPagination a.prevPagination , | ||
227 | .controlPagination a.noPrevPagination, | ||
228 | .controlPagination a.nextPagination, | ||
229 | .controlPagination a.noNextPagination { | ||
230 | background-image:url($xwiki.getSkinFile("navigation.png")); | ||
231 | width: 21px; | ||
232 | height: 22px; | ||
233 | } | ||
234 | .controlPagination a.prevPagination { | ||
235 | background-position:left top; | ||
236 | } | ||
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; | ||
247 | } | ||
248 | {{/code}} | ||
249 | |||
250 | === HTML Code === | ||
251 | |||
252 | {{code}} | ||
253 | <div class="paginationFooter"> | ||
254 | <div class="paginationFilter"> | ||
255 | <span class="controlPagination"> | ||
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> | ||
258 | </span> | ||
259 | <span class="pagination"> | ||
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> | ||
270 | </span> | ||
271 | </div> | ||
272 | </div> | ||
273 | {{/code}} | ||
274 | |||
275 | == <span id="dependencies"> Dependencies</span> == | ||
276 | |||
277 | === Icons === | ||
278 | |||
279 | navigation.png | ||
280 | <p/> | ||
281 | [[image:navigation.png]] | ||
282 | |||
283 | === Translations === | ||
284 | |||
285 | ==== Sort Translations ==== | ||
286 | |||
287 | xe.search.filters.sort=Sort: | ||
288 | <p/> | ||
289 | xe.search.filters.relevance=Relevance | ||
290 | <p/> | ||
291 | xe.search.filters.relevance.title=Sort by Relevance | ||
292 | <p/> | ||
293 | xe.search.filters.date=Date | ||
294 | <p/> | ||
295 | xe.search.filters.date.title=Sort by Date | ||
296 | <p/> | ||
297 | xe.search.filters.rating=Rating | ||
298 | <p/> | ||
299 | xe.search.filters.rating.title=Sort by Rating | ||
300 | <p/> | ||
301 | xe.search.filters.popularity=Popularity | ||
302 | <p/> | ||
303 | xe.search.filters.popularity.title=Sort by Popularity | ||
304 | |||
305 | ==== Navigation Translations ==== | ||
306 | |||
307 | xe.pagination.results=Results | ||
308 | <p/> | ||
309 | xe.pagination.results.of=out of | ||
310 | <p/> | ||
311 | xe.pagination.page=Page | ||
312 | <p/> | ||
313 | xe.pagination.page.title=Page {0} | ||
314 | <p/> | ||
315 | xe.pagination.page.prev.title=Previous Page | ||
316 | <p/> | ||
317 | xe.pagination.page.next.title=Next Page | ||
318 | |||
319 | == Velocity Macro == | ||
320 | |||
321 | {{code language="none"}}#pagination($parameters){{/code}} | ||
322 | |||
323 | The macro is responsible for displaying browsing links, and does not involve the actual display of the browsed items. | ||
324 | <p/> | ||
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> | ||
329 | <dd>Default: $doc.getURL('view')</dd> | ||
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> | ||
348 | <p/> | ||
349 | Usage example: | ||
350 | |||
351 | {{code language="none"}} | ||
352 | #set($paginationParameters = { | ||
353 | 'url' : $doc.getURL('view', "text=${query}"), | ||
354 | 'totalItems' : $searchresults.getHitcount(), | ||
355 | 'defaultItemsPerPage' : $defaultItemsPerPage, | ||
356 | 'position': 'top' | ||
357 | }) | ||
358 | #pagination($paginationParameters) | ||
359 | {{/code}} | ||
360 | |||
361 | === Example === | ||
362 | |||
363 | The pagination macro can be used for example to display the latest modifications of the current user: | ||
364 | |||
365 | {{code language="none"}} | ||
366 | #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true)) | ||
367 | #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true)) | ||
368 | ## | ||
369 | ## set display parameters for the list | ||
370 | ## | ||
371 | #set($defaultItemsPerPage = 10) | ||
372 | #set($orderClause = "order by doc.date desc") | ||
373 | #set($whereClause = "where 1=1 and doc.author='$context.user'") | ||
374 | #set($results_url = $doc.getURL('view')) | ||
375 | #set($totalItems = $xwiki.countDocuments($whereClause)) | ||
376 | #if($totalItems > 0) | ||
377 | ## ----------------- | ||
378 | ## Pagination (top) | ||
379 | ## ----------------- | ||
380 | #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) | ||
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)) | ||
393 | #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex)) | ||
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 | ||
403 | {{/code}} | ||
404 | |||
405 | #if(!$isGuest) | ||
406 | #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true)) | ||
407 | #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true)) | ||
408 | ## | ||
409 | ## set display parameters for the list | ||
410 | ## | ||
411 | #set($defaultItemsPerPage = 10) | ||
412 | #set($orderClause = "order by doc.date desc") | ||
413 | #set($whereClause = "where 1=1 and doc.author='$context.user'") | ||
414 | #set($results_url = $doc.getURL('view')) | ||
415 | #set($totalItems = $xwiki.countDocuments($whereClause)) | ||
416 | #if($totalItems > 0) | ||
417 | ## ----------------- | ||
418 | ## Pagination (top) | ||
419 | ## ----------------- | ||
420 | #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) | ||
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)) | ||
433 | #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex)) | ||
434 | #set ($list = $results) | ||
435 | #set ($isScored = false) | ||
436 | {{include document="XWiki.Results"/}} | ||
437 | ## ----------------- | ||
438 | ## Pagination (bottom) | ||
439 | ## ----------------- | ||
440 | #set($paginationParameters.position = 'bottom') | ||
441 | #pagination($paginationParameters) | ||
442 | #end | ||
443 | #end | ||
444 | |||
445 | {{/html}} | ||
446 | {{/velocity}} |