Wiki source code of Pagination
Last modified by Vincent Massol on 2017/09/04
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{box cssClass="floatinginfobox" title="**Contents**"}} | ||
2 | {{toc/}} | ||
3 | {{/box}} | ||
4 | |||
5 | {{info}} | ||
6 | This was committed in 1.9RC1. See [[this Jira issue>>https://jira.xwiki.org/browse/XWIKI-3880]] for details. | ||
7 | {{/info}} | ||
8 | |||
9 | = Example = | ||
10 | |||
11 | See [[ListWebSearch>>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 | = Bottom Navigation = | ||
160 | |||
161 | [[image:Example-BottomNavigation.png||width="950"]] | ||
162 | |||
163 | This is a lighter version of the Upper Navigation, keeping only the pagination controls. | ||
164 | |||
165 | == CSS == | ||
166 | |||
167 | Container: | ||
168 | |||
169 | {{code}} | ||
170 | .paginationFooter{ | ||
171 | display: block; | ||
172 | clear: both; | ||
173 | text-align: right; | ||
174 | font-size: 90%; | ||
175 | } | ||
176 | {{/code}} | ||
177 | |||
178 | Same as in Upper navigation (don't apply if both navigations are present): | ||
179 | |||
180 | {{code}} | ||
181 | .paginationFilter { | ||
182 | color: #888; | ||
183 | height: 100%; | ||
184 | border-top: 1px solid #CCCCCC; | ||
185 | padding: 2px 0px 5px 5px; | ||
186 | display: block; | ||
187 | line-height: 22px; | ||
188 | } | ||
189 | .pagination{ | ||
190 | float: right; | ||
191 | margin-right: 10px; | ||
192 | } | ||
193 | .pagination a{ | ||
194 | color: #888; | ||
195 | } | ||
196 | .pagination a:hover{ | ||
197 | color: #4D4D4D; | ||
198 | } | ||
199 | .pagination a.currentPagination{ | ||
200 | color: #4D4D4D; | ||
201 | font-weight: bold; | ||
202 | } | ||
203 | .pagination a:focus { | ||
204 | outline: dotted 1px #000; | ||
205 | } | ||
206 | .controlPagination{ | ||
207 | position:relative; | ||
208 | width:42px; | ||
209 | height:22px; | ||
210 | overflow:hidden; | ||
211 | margin:0!important; | ||
212 | padding:0!important; | ||
213 | float: right; | ||
214 | } | ||
215 | .controlPagination a{ | ||
216 | position:absolute; | ||
217 | top:0; | ||
218 | left:0; | ||
219 | line-height:25px; | ||
220 | outline:none; | ||
221 | overflow:hidden; | ||
222 | border:none; | ||
223 | } | ||
224 | .controlPagination a.prevPagination , | ||
225 | .controlPagination a.noPrevPagination, | ||
226 | .controlPagination a.nextPagination, | ||
227 | .controlPagination a.noNextPagination { | ||
228 | background-image:url($xwiki.getSkinFile("navigation.png")); | ||
229 | width: 21px; | ||
230 | height: 22px; | ||
231 | } | ||
232 | .controlPagination a.prevPagination { | ||
233 | background-position:left top; | ||
234 | } | ||
235 | .controlPagination a.noPrevPagination{ | ||
236 | background-position:left bottom; | ||
237 | } | ||
238 | .controlPagination a.nextPagination { | ||
239 | background-position:right top; | ||
240 | left: 21px; | ||
241 | } | ||
242 | .controlPagination a.noNextPagination { | ||
243 | background-position:right bottom; | ||
244 | left: 21px; | ||
245 | } | ||
246 | {{/code}} | ||
247 | |||
248 | == HTML Code == | ||
249 | |||
250 | {{code}} | ||
251 | <div class="paginationFooter"> | ||
252 | <div class="paginationFilter"> | ||
253 | <span class="controlPagination"> | ||
254 | <a href="#" title="$msg.get('xe.pagination.page.prev.title')" class="noPrevPagination"></a> | ||
255 | <a href="#" title="$msg.get('xe.pagination.page.next.title')" class="noNextPagination"></a> | ||
256 | </span> | ||
257 | <span class="pagination"> | ||
258 | $msg.get("xe.pagination.page") | ||
259 | <a href="" title="$msg.get('xe.pagination.page.title',['1'])">1</a> | ||
260 | <a href="" class="currentPagination" title="$msg.get('xe.pagination.page.title',['2'])">2</a> | ||
261 | <a href="" title="$msg.get('xe.pagination.page.title',['3'])">3</a> | ||
262 | <a href="" title="$msg.get('xe.pagination.page.title',['4'])">4</a> | ||
263 | <a href="" title="$msg.get('xe.pagination.page.title',['5'])">5</a> | ||
264 | <a href="" title="$msg.get('xe.pagination.page.title',['6'])">6</a> | ||
265 | <a href="" title="$msg.get('xe.pagination.page.title',['7'])">7</a> | ||
266 | <a href="" title="$msg.get('xe.pagination.page.title',['8'])">8</a> | ||
267 | <a href="" title="$msg.get('xe.pagination.page.title',['9'])">9</a> | ||
268 | </span> | ||
269 | </div> | ||
270 | </div> | ||
271 | {{/code}} | ||
272 | |||
273 | = Dependencies = | ||
274 | |||
275 | == Icons == | ||
276 | |||
277 | [[image:navigation.png]] | ||
278 | |||
279 | == Translations == | ||
280 | |||
281 | === Sort Translations === | ||
282 | |||
283 | {{code}} | ||
284 | xe.search.filters.sort=Sort: | ||
285 | xe.search.filters.relevance=Relevance | ||
286 | xe.search.filters.relevance.title=Sort by Relevance | ||
287 | xe.search.filters.date=Date | ||
288 | xe.search.filters.date.title=Sort by Date | ||
289 | xe.search.filters.rating=Rating | ||
290 | xe.search.filters.rating.title=Sort by Rating | ||
291 | xe.search.filters.popularity=Popularity | ||
292 | xe.search.filters.popularity.title=Sort by Popularity | ||
293 | {{/code}} | ||
294 | |||
295 | === Navigation Translations === | ||
296 | |||
297 | {{code}} | ||
298 | xe.pagination.results=Results | ||
299 | xe.pagination.results.of=out of | ||
300 | xe.pagination.page=Page | ||
301 | xe.pagination.page.title=Page {0} | ||
302 | xe.pagination.page.prev.title=Previous Page | ||
303 | xe.pagination.page.next.title=Next Page | ||
304 | {{/code}} | ||
305 | |||
306 | = Velocity Macro = | ||
307 | |||
308 | {{code language="none"}} | ||
309 | #pagination($parameters) | ||
310 | {{/code}} | ||
311 | |||
312 | The macro is responsible for displaying browsing links, and does not involve the actual display of the browsed items. | ||
313 | |||
314 | It accepts a single argument, which in turn is a map of parameters: | ||
315 | |||
316 | ; url | ||
317 | : The base url of the document displaying the collection. | ||
318 | : Default: {{velocity}}$doc.getURL('view'){{/velocity}} | ||
319 | ; totalItems | ||
320 | : The total number number of items in the collection. | ||
321 | : Default: none, this parameter is mandatory. | ||
322 | ; defaultItemsPerPage | ||
323 | : The number of items per page. This value is overwritten by the request parameter "perPage", if it exists and has a valid positive integer value. | ||
324 | : Default: 20 | ||
325 | ; position | ||
326 | : The placement of the pagination widget. Supported values: "top", "bottom". The bottom widget only displays pages, while the top widget also provides a information about the item range on the current page. | ||
327 | : Default: top | ||
328 | ; itemParamName | ||
329 | : The name of the request parameter for the index of the first displayed item. | ||
330 | : Default: firstIndex | ||
331 | ; itemsPerPageParamName | ||
332 | : The name of the request parameter for the number of items displayed on a page. | ||
333 | : Default: perPage | ||
334 | |||
335 | Usage example: | ||
336 | |||
337 | {{code language="none"}} | ||
338 | #set($paginationParameters = { | ||
339 | 'url' : $doc.getURL('view', "text=${query}"), | ||
340 | 'totalItems' : $searchresults.getHitcount(), | ||
341 | 'defaultItemsPerPage' : $defaultItemsPerPage, | ||
342 | 'position': 'top' | ||
343 | }) | ||
344 | #pagination($paginationParameters) | ||
345 | {{/code}} | ||
346 | |||
347 | == Example == | ||
348 | |||
349 | The pagination macro can be used for example to display the latest modifications of the current user: | ||
350 | |||
351 | {{code}} | ||
352 | |||
353 | #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true)) | ||
354 | #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true)) | ||
355 | ## | ||
356 | ## set display parameters for the list | ||
357 | ## | ||
358 | #set($defaultItemsPerPage = 10) | ||
359 | #set($orderClause = "order by doc.date desc") | ||
360 | #set($whereClause = "where 1=1 and doc.author='$context.user'") | ||
361 | #set($results_url = $doc.getURL('view')) | ||
362 | #set($totalItems = $xwiki.countDocuments($whereClause)) | ||
363 | #if($totalItems > 0) | ||
364 | ## ----------------- | ||
365 | ## Pagination (top) | ||
366 | ## ----------------- | ||
367 | #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) | ||
368 | #pagination($paginationParameters) | ||
369 | ## ----------------- | ||
370 | ## Display results | ||
371 | ## ----------------- | ||
372 | #set($firstIndex = "$!{paginationParameters.firstItem}") | ||
373 | #if($firstIndex == '') | ||
374 | #set($firstIndex = "$!request.getParameter('firstIndex')") | ||
375 | #if($firstIndex == '') | ||
376 | #set($firstIndex = '0') | ||
377 | #end | ||
378 | #end | ||
379 | #set($firstIndex = $util.parseInt($firstIndex)) | ||
380 | #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex)) | ||
381 | #set ($list = $results) | ||
382 | #set ($isScored = false) | ||
383 | #includeInContext("XWiki.Results") | ||
384 | ## ----------------- | ||
385 | ## Pagination (bottom) | ||
386 | ## ----------------- | ||
387 | #set($paginationParameters.position = 'bottom') | ||
388 | #pagination($paginationParameters) | ||
389 | #end | ||
390 | {{/code}} | ||
391 | |||
392 | {{velocity}} | ||
393 | #if(!$isGuest) | ||
394 | #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true)) | ||
395 | #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true)) | ||
396 | ## | ||
397 | ## set display parameters for the list | ||
398 | ## | ||
399 | #set($defaultItemsPerPage = 10) | ||
400 | #set($orderClause = "order by doc.date desc") | ||
401 | #set($whereClause = "where 1=1 and doc.author='$context.user'") | ||
402 | #set($results_url = $doc.getURL('view')) | ||
403 | #set($totalItems = $xwiki.countDocuments($whereClause)) | ||
404 | #if($totalItems > 0) | ||
405 | ## ----------------- | ||
406 | ## Pagination (top) | ||
407 | ## ----------------- | ||
408 | #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) | ||
409 | {{html wiki="true" clean="false"}} | ||
410 | #pagination($paginationParameters) | ||
411 | {{/html}} | ||
412 | ## ----------------- | ||
413 | ## Display results | ||
414 | ## ----------------- | ||
415 | #set($firstIndex = "$!{paginationParameters.firstItem}") | ||
416 | #if($firstIndex == '') | ||
417 | #set($firstIndex = "$!request.getParameter('firstIndex')") | ||
418 | #if($firstIndex == '') | ||
419 | #set($firstIndex = '0') | ||
420 | #end | ||
421 | #end | ||
422 | #set($firstIndex = $util.parseInt($firstIndex)) | ||
423 | #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex)) | ||
424 | #set ($list = $results) | ||
425 | #set ($isScored = false) | ||
426 | {{include document="XWiki.Results"/}} | ||
427 | ## ----------------- | ||
428 | ## Pagination (bottom) | ||
429 | ## ----------------- | ||
430 | #set($paginationParameters.position = 'bottom') | ||
431 | {{html wiki="true" clean="false"}} | ||
432 | #pagination($paginationParameters) | ||
433 | {{/html}} | ||
434 | #end | ||
435 | #end | ||
436 | {{/velocity}} |