FreeMarker pagination macros

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.

1,027 thoughts on “FreeMarker pagination macros

  1. online pokies canada legal, best payout online casino usa and vancouver australia casinos,
    or no deposit bonus how much do you tip casino hosts
    (Johnnie) microgaming australia

  2. can i use td australia visa debit for online gambling, casino nsw united states and betway poker australia,
    or how to play united statesn poker

    My page – vegas vacation blackjack dealer (Josefa)

  3. united states online casino real money, new zealandn poker online free game
    and gambling issues in australia, or free united statesn slot machine games

    Feel free to visit my blog post – 27 roulette wheel, Andrew,

  4. online pokies positive effects of gambling
    on society, Earnest, australia,
    united kingdom online play roulette and roulette australia rules,
    or bingo online for money united kingdom

  5. poker united statesno gratis, black chip poker united kingdom and online casino
    united states review, or blackjack tutorial usa

    Here is my web page :: best place to learn craps in vegas (Alena)

  6. can i use td australia visa debit for online gambling, online what
    is a good casino app for android (Ollie) no deposit bonus no download instant play united states and usa free bingo prize,
    or netent no deposit bonus nz

  7. no deposit bingo bonus usa, best deposit bonus uk and spin palace casino canada download,
    or apple pay online casino united states

    My page :: craps lay vs buy (Norma)

  8. free spins casino no deposit bonus canada, how to memorize united statesn roulette
    wheel and australian online no deposit casino, or online roulette for real money usa

    My website bingo win cash prizes (Brooke)

  9. usa bingo search pound, huuuge free casino chips (Jude) sites usa no
    deposit bonus and canada offshore gambling, or new zealands
    best onlinecasinos gambling com

  10. is can i create a gambling website [Gale]
    allowed in united states, best online pokies united kingdom forum
    and best slot sites australia, or awesome online casino new zealand

  11. no deposit bonus free spins uk, uk casino reward card (Katlyn) sites with no wagering requirements and united
    statesn online slots real money, or are there casinos in usa

  12. online free casino united states, free pokie games
    united kingdom and free bonus no deposit uk slots, or online vegas
    legends casino (Cassie) new usa

  13. native united statesn gambling rights, new zealandn roulette table and
    the largest casino what does gamble mean in french,
    Reina, australia, or uk gambling license
    conditions

  14. gold coast casino australia, pokies meaning australia and online casino united statesn legal
    real money no deposit bonus, or most legit online casino united states

    Here is my web-site – craps app with hop bets – Taylah -

  15. eur 20 free no deposit casino uk 2021, united
    kingdom casino in vegas and dollar 5 deposit online malabon grand casino games (Jani) australia, or best slot games online uk

  16. new zealand pokies app, african new zealandns
    gambling in vegas and roulette chooser online (Lindsey) casino australia real
    money 2021, or united states slots machines

  17. gambling online in usa, are there any legal online poker sites in australia and
    online slot casino uk, or poker with real money usa

    Feel free to visit my site :: betnspin no deposit bonus codes, Charity,

  18. canadian online live blackjack, can you play poker online united kingdom
    and bet365 play new zealandn roulette online uk, or online casino reviews united states

    Feel free to surf to my site; negative impact of gambling on businesses; Gilda,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>