Wiki source code of Pagination

Version 27.1 by Thomas Mortagne on 2017/03/24

Hide last authors
Manuel Smeria 26.13 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
Guillaume Lerouge 1.1 4
Manuel Smeria 26.1 5 {{info}}
Thomas Mortagne 27.1 6 This was committed in 1.9RC1. See [[this Jira issue>>https://jira.xwiki.org/jira/browse/XWIKI-3880]] for details.
Manuel Smeria 26.1 7 {{/info}}
Guillaume Lerouge 1.1 8
Manuel Smeria 26.13 9 = Example =
Guillaume Lerouge 2.1 10
Manuel Smeria 26.13 11 See [[ListWebSearch>>http://incubator.myxwiki.org/xwiki/bin/view/Main/ListWebSearch]]
Guillaume Lerouge 2.1 12
Manuel Smeria 26.1 13 == Upper navigation ==
Ecaterina Moraru (Valica) 17.2 14
Manuel Smeria 26.1 15 [[image:Example-UpperNavigation.png||width="950"]]
Ecaterina Moraru (Valica) 3.1 16
Manuel Smeria 26.13 17 == CSS ==
Manuel Smeria 26.1 18
Ecaterina Moraru (Valica) 7.1 19 Filters CSS:
Manuel Smeria 26.1 20
21 {{code}}
Ecaterina Moraru (Valica) 4.1 22 .searchFilters{
23 clear: both;
24 font-size: 90%;
25 }
26 #sortFilter{
Ecaterina Moraru (Valica) 17.10 27 color: #888;
Ecaterina Moraru (Valica) 4.1 28 padding: 5px;
29 line-height: 16px;
30 }
31 #sortFilter a.sortType{
Ecaterina Moraru (Valica) 17.10 32 color: #888;
Ecaterina Moraru (Valica) 4.1 33 }
34 #sortFilter a.sortType:hover{
35 color: #4D4D4D;
36 }
37 #sortFilter a#currentSort{
38 color: #4D4D4D;
39 font-weight: bold;
40 }
Ecaterina Moraru (Valica) 5.1 41 #sortFilter a.sortType:focus,
42 #sortFilter a#currentSort:focus {
Ecaterina Moraru (Valica) 4.1 43 outline: dotted 1px #000;
44 }
Manuel Smeria 26.1 45 {{/code}}
Guillaume Lerouge 1.1 46
Ecaterina Moraru (Valica) 7.1 47 Pagination with number of result pages displayed:
Manuel Smeria 26.1 48
49 {{code}}
Ecaterina Moraru (Valica) 4.1 50 .paginationFilter {
Ecaterina Moraru (Valica) 17.10 51 color: #888;
Ecaterina Moraru (Valica) 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{
Ecaterina Moraru (Valica) 17.10 62 color: #888;
Ecaterina Moraru (Valica) 4.1 63 }
64 .pagination{
65 float: right;
66 margin-right: 10px;
67 }
68 .pagination a{
Ecaterina Moraru (Valica) 17.10 69 color: #888;
Ecaterina Moraru (Valica) 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 }
Ecaterina Moraru (Valica) 17.12 99 .controlPagination a.prevPagination ,
100 .controlPagination a.noPrevPagination,
101 .controlPagination a.nextPagination,
102 .controlPagination a.noNextPagination {
Ecaterina Moraru (Valica) 4.1 103 background-image:url($xwiki.getSkinFile("navigation.png"));
104 width: 21px;
105 height: 22px;
106 }
Ecaterina Moraru (Valica) 17.12 107 .controlPagination a.prevPagination {
108 background-position:left top;
109 }
Ecaterina Moraru (Valica) 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;
Ecaterina Moraru (Valica) 17.12 120 }
Manuel Smeria 26.1 121 {{/code}}
Ecaterina Moraru (Valica) 4.1 122
Manuel Smeria 26.13 123 == HTML Code ==
Guillaume Lerouge 1.1 124
Manuel Smeria 26.1 125 {{code}}
Ecaterina Moraru (Valica) 3.1 126 <div class="searchFilters">
Ecaterina Moraru (Valica) 4.1 127
Ecaterina Moraru (Valica) 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">
Ecaterina Moraru (Valica) 4.1 137
Ecaterina Moraru (Valica) 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>
Ecaterina Moraru (Valica) 4.1 139
Ecaterina Moraru (Valica) 3.1 140 <span class="controlPagination">
Ecaterina Moraru (Valica) 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>
Ecaterina Moraru (Valica) 3.1 143 </span>
Ecaterina Moraru (Valica) 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>
Ecaterina Moraru (Valica) 3.1 154 </span>
155 </div>
156 </div>
Manuel Smeria 26.1 157 {{/code}}
Ecaterina Moraru (Valica) 3.1 158
Manuel Smeria 26.13 159 = Bottom Navigation =
Ecaterina Moraru (Valica) 3.1 160
Manuel Smeria 26.1 161 [[image:Example-BottomNavigation.png||width="950"]]
Manuel Smeria 26.13 162
Ecaterina Moraru (Valica) 7.1 163 This is a lighter version of the Upper Navigation, keeping only the pagination controls.
164
Manuel Smeria 26.13 165 == CSS ==
Ecaterina Moraru (Valica) 3.1 166
Ecaterina Moraru (Valica) 7.1 167 Container:
Manuel Smeria 26.1 168
169 {{code}}
Ecaterina Moraru (Valica) 4.1 170 .paginationFooter{
171 display: block;
172 clear: both;
173 text-align: right;
174 font-size: 90%;
175 }
Manuel Smeria 26.1 176 {{/code}}
Ecaterina Moraru (Valica) 3.1 177
Ecaterina Moraru (Valica) 17.12 178 Same as in Upper navigation (don't apply if both navigations are present):
Manuel Smeria 26.1 179
180 {{code}}
Ecaterina Moraru (Valica) 4.1 181 .paginationFilter {
Ecaterina Moraru (Valica) 17.10 182 color: #888;
Ecaterina Moraru (Valica) 4.1 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{
Ecaterina Moraru (Valica) 17.10 194 color: #888;
Ecaterina Moraru (Valica) 4.1 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 }
Ecaterina Moraru (Valica) 17.12 224 .controlPagination a.prevPagination ,
225 .controlPagination a.noPrevPagination,
226 .controlPagination a.nextPagination,
227 .controlPagination a.noNextPagination {
Ecaterina Moraru (Valica) 4.1 228 background-image:url($xwiki.getSkinFile("navigation.png"));
229 width: 21px;
230 height: 22px;
231 }
Ecaterina Moraru (Valica) 17.12 232 .controlPagination a.prevPagination {
233 background-position:left top;
234 }
Ecaterina Moraru (Valica) 4.1 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;
Ecaterina Moraru (Valica) 17.12 245 }
Manuel Smeria 26.1 246 {{/code}}
Ecaterina Moraru (Valica) 4.1 247
Manuel Smeria 26.13 248 == HTML Code ==
Ecaterina Moraru (Valica) 3.1 249
Manuel Smeria 26.1 250 {{code}}
Ecaterina Moraru (Valica) 4.1 251 <div class="paginationFooter">
252 <div class="paginationFilter">
253 <span class="controlPagination">
Ecaterina Moraru (Valica) 18.1 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>
Ecaterina Moraru (Valica) 4.1 256 </span>
257 <span class="pagination">
Ecaterina Moraru (Valica) 18.1 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>
Ecaterina Moraru (Valica) 4.1 268 </span>
269 </div>
270 </div>
Manuel Smeria 26.1 271 {{/code}}
Guillaume Lerouge 1.1 272
Manuel Smeria 26.13 273 = Dependencies =
Ecaterina Moraru (Valica) 8.1 274
Manuel Smeria 26.13 275 == Icons ==
Ecaterina Moraru (Valica) 8.1 276
Manuel Smeria 26.1 277 [[image:navigation.png]]
Ecaterina Moraru (Valica) 8.1 278
Manuel Smeria 26.13 279 == Translations ==
Ecaterina Moraru (Valica) 17.4 280
Manuel Smeria 26.13 281 === Sort Translations ===
Ecaterina Moraru (Valica) 8.1 282
Manuel Smeria 26.6 283 {{code}}
Ecaterina Moraru (Valica) 8.1 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
Manuel Smeria 26.6 293 {{/code}}
Ecaterina Moraru (Valica) 8.1 294
Manuel Smeria 26.13 295 === Navigation Translations ===
Ecaterina Moraru (Valica) 8.1 296
Manuel Smeria 26.6 297 {{code}}
Ecaterina Moraru (Valica) 18.1 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
Manuel Smeria 26.6 304 {{/code}}
Ecaterina Moraru (Valica) 8.1 305
Manuel Smeria 26.13 306 = Velocity Macro =
Sergiu Dumitriu 20.1 307
Manuel Smeria 26.1 308 {{code language="none"}}#pagination($parameters){{/code}}
Sergiu Dumitriu 20.1 309
310 The macro is responsible for displaying browsing links, and does not involve the actual display of the browsed items.
Manuel Smeria 26.13 311
Sergiu Dumitriu 20.1 312 It accepts a single argument, which in turn is a map of parameters:
Manuel Smeria 26.13 313
314 ; url
315 : The base url of the document displaying the collection.
316 : Default: {{velocity}}$doc.getURL('view'){{/velocity}}
317 ; totalItems
318 : The total number number of items in the collection.
319 : Default: none, this parameter is mandatory.
320 ; defaultItemsPerPage
321 : 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.
322 : Default: 20
323 ; position
324 : 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.
325 : Default: top
326 ; itemParamName
327 : The name of the request parameter for the index of the first displayed item.
328 : Default: firstIndex
329 ; itemsPerPageParamName
330 : The name of the request parameter for the number of items displayed on a page.
331 : Default: perPage
332
Manuel Smeria 26.1 333 Usage example:
Manuel Smeria 24.1 334
Manuel Smeria 26.1 335 {{code language="none"}}
Sergiu Dumitriu 20.1 336 #set($paginationParameters = {
337 'url' : $doc.getURL('view', "text=${query}"),
338 'totalItems' : $searchresults.getHitcount(),
339 'defaultItemsPerPage' : $defaultItemsPerPage,
340 'position': 'top'
341 })
342 #pagination($paginationParameters)
Manuel Smeria 26.1 343 {{/code}}
Oana Florea 21.1 344
Manuel Smeria 26.13 345 == Example ==
Oana Florea 21.1 346
347 The pagination macro can be used for example to display the latest modifications of the current user:
348
Manuel Smeria 26.7 349 {{code}}
Manuel Smeria 26.8 350
Manuel Smeria 26.1 351 #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true))
Oana Florea 21.1 352 #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true))
353 ##
354 ## set display parameters for the list
355 ##
356 #set($defaultItemsPerPage = 10)
Oana Florea 22.1 357 #set($orderClause = "order by doc.date desc")
358 #set($whereClause = "where 1=1 and doc.author='$context.user'")
Oana Florea 21.1 359 #set($results_url = $doc.getURL('view'))
Oana Florea 22.1 360 #set($totalItems = $xwiki.countDocuments($whereClause))
361 #if($totalItems > 0)
Oana Florea 21.1 362 ## -----------------
363 ## Pagination (top)
364 ## -----------------
Oana Florea 22.1 365 #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'})
Oana Florea 21.1 366 #pagination($paginationParameters)
367 ## -----------------
368 ## Display results
369 ## -----------------
370 #set($firstIndex = "$!{paginationParameters.firstItem}")
371 #if($firstIndex == '')
372 #set($firstIndex = "$!request.getParameter('firstIndex')")
373 #if($firstIndex == '')
374 #set($firstIndex = '0')
375 #end
376 #end
377 #set($firstIndex = $util.parseInt($firstIndex))
Oana Florea 22.1 378 #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex))
Oana Florea 21.1 379 #set ($list = $results)
380 #set ($isScored = false)
381 #includeInContext("XWiki.Results")
382 ## -----------------
383 ## Pagination (bottom)
384 ## -----------------
385 #set($paginationParameters.position = 'bottom')
386 #pagination($paginationParameters)
387 #end
Manuel Smeria 26.1 388 {{/code}}
Manuel Smeria 26.9 389
Manuel Smeria 26.3 390 {{velocity}}
Oana Florea 21.1 391 #if(!$isGuest)
Oana Florea 22.1 392 #set($ok = $xwiki.jsfx.use("uicomponents/search/search.js", true))
393 #set($ok = $xwiki.ssfx.use("uicomponents/search/search.css", true))
Oana Florea 21.1 394 ##
395 ## set display parameters for the list
396 ##
397 #set($defaultItemsPerPage = 10)
Oana Florea 22.1 398 #set($orderClause = "order by doc.date desc")
399 #set($whereClause = "where 1=1 and doc.author='$context.user'")
Oana Florea 21.1 400 #set($results_url = $doc.getURL('view'))
Oana Florea 22.1 401 #set($totalItems = $xwiki.countDocuments($whereClause))
402 #if($totalItems > 0)
Oana Florea 21.1 403 ## -----------------
404 ## Pagination (top)
405 ## -----------------
Oana Florea 22.1 406 #set($paginationParameters = {'url' : $results_url, 'totalItems' : $totalItems, 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'})
Manuel Smeria 26.12 407 {{html wiki="true" clean="false"}}
408 #pagination($paginationParameters)
409 {{/html}}
Oana Florea 21.1 410 ## -----------------
411 ## Display results
412 ## -----------------
413 #set($firstIndex = "$!{paginationParameters.firstItem}")
414 #if($firstIndex == '')
415 #set($firstIndex = "$!request.getParameter('firstIndex')")
416 #if($firstIndex == '')
417 #set($firstIndex = '0')
418 #end
419 #end
420 #set($firstIndex = $util.parseInt($firstIndex))
Oana Florea 22.1 421 #set($results = $xwiki.searchDocuments("$whereClause $orderClause", $defaultItemsPerPage, $firstIndex))
Oana Florea 21.1 422 #set ($list = $results)
423 #set ($isScored = false)
Manuel Smeria 26.1 424 {{include document="XWiki.Results"/}}
Oana Florea 21.1 425 ## -----------------
426 ## Pagination (bottom)
427 ## -----------------
428 #set($paginationParameters.position = 'bottom')
Manuel Smeria 26.12 429 {{html wiki="true" clean="false"}}
430 #pagination($paginationParameters)
431 {{/html}}
Oana Florea 21.1 432 #end
433 #end
Manuel Smeria 26.3 434 {{/velocity}}

Get Connected