I couldn’t find a good set of macros to help navigate through paginated data so I wrote my own. The macro names echo the names of the CakePHP PaginationHelper functions because…well, they’re reasonably sensible.
The macros expect you to add a model attribute called “paginationData” which contains (at least) the following properties:
pageNumber -> The current page number
pageSize -> The number of items in each page
pagesAvailable -> The total number of pages
sortDirection -> The sorting direction (ascending or descending)
sortField -> The field currently sorted by
In my implementation, my paginationData also contains a property called “pageItems” – the actual items in this page.
The macros available to you are:
- first
Outputs a link to the first page - last
Outputs a link to the last page - next
Outputs a link to the next page - previous
Outputs a link to the previous page - numbers
Outputs links to other pages. The macro takes a parameter called “maxPages”, which is the maximum number of pages that should be output. There is also a second parameter “separator”, which is the text/html that should be output between each page link. - page
Outputs a link to a particular page. It takes the page number and link text as parameters. If you omit the link text it’ll default to the page number - counter
Outputs the current page number and the total pages e.g. “1 of 20″ - sort
Outputs a link to sort by a field. Takes the field to sort by as its first parameter. If field is different to the current sort field, the link will change the sort field but not the sort direction. If the field is the same as the current sort field, the link will change the sort direction. The second parameter is the link text, which defaults to the field name with an upper case first letter. It also takes a parameter called “directions”. This is an an array of two items: the words being used in paginationData.sortDirection to describe the sorting direction of ascending or descending. Default: ["Asc", "Desc"]. So it can compare the current sorting direction and switch to the converse.
Note, ordinarily you’ll probably not need to use the “page” macro.
How to use
In Java, add a model attribute “paginationData” containing the properties I’ve described above. Then, in your view, import the library:
<#import "pagination.ftl" as pagination />
Call the macros:
<nav style="float:right;"> <@pagination.first /> <@pagination.previous /> <@pagination.numbers /> <@pagination.next /> <@pagination.last /> </nav> <@pagination.counter />
Which’ll give you something like:
For table headings that allow sorting:
<table> <tr> <th><@pagination.sort "forename" /></th> <th><@pagination.sort "surname" /></th> <th><@pagination.sort "email" /></th> <th><@pagination.sort "created" "Registration date" /></th> </tr> ... </table>
Download
You can download the pagination macros here.
Hello,
I got the following error :
Error executing FreeMarker template
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> spring [in template "common/paginatedList.ftl" at line 74, column 11]
could you help me to find what is spring?
i don’t really know, but i think that this is just a text output. spring is supposed to get a text from a resource along with a default value if this resource is empty. you could substitute this with just text.
Activation of the low pH o conditioned current cialis
I am in fact pleased to glance at this webpage posts which includes tons of valuable information,
thanks for providing these statistics.
About 1 in 20 women of childbearing age have the disorder priligy medicine 97; p p p B Estradiol produced a rightward shift in the cumulative percentile of CREB fluorescence under basal conditions
There were times it was hard on our marriage but I think that either of us would say that it was actually something that strengthened our marriage priligy buy Synergy of combined Doxycycline TUDCA treatment in lowering Transthyretin deposition and associated biomarkers studies in FAP mouse models
buy priligy in the us We did not detect any difference in heart failure related quality of life which was the outcome we powered our study to detect
His past history was notable for controlled type 2 diabetes mellitus for 8 years hypertension hyperlipidemia and spinal stenosis precio priligy 30 mg alesse bupropion farmacia guadalajara All the remains were complete in the plane Venezuelan Attorney General Luisa Ortega told reporters