[Catalyst] Re: OT: Better TT pager?

Zbigniew Lukasiak zzbbyy at gmail.com
Sat Feb 28 09:44:20 GMT 2009


On Thu, Jan 22, 2009 at 4:48 PM, Oliver Charles
<oliver.g.charles at googlemail.com> wrote:
> I might as well join in with this :) Here's what we use at work:
>
> [% IF pager %]
>    <ul class="paginator">
>        <li class="counter">Page [% pager.current_page %] of [%
> pager.last_page %]</li>
>        <li><a href="[% c.req.uri_with( page => pager.first_page )
> %]">&laquo;</a></li>
>        [% IF pager.previous_page %]
>            <li><a href="[% c.req.uri_with( page =>
> pager.previous_page ) %]">&lt;</a></li>
>        [% END %]
>
>        [% start = (pager.current_page - 3) > 0 ? (pager.current_page - 3) : 1;
>         FOREACH page IN [ start .. pager.last_page ] %]
>            [% LAST IF loop.count > 6 %]
>            <li[% IF pager.current_page == page; ' class="current"'; END %]>
>                <a href="[% c.req.uri_with( page => page ) %]">[% page %]</a>
>            </li>
>        [% END %]
>
>        [% IF pager.next_page %]
>            <li><a href="[% c.req.uri_with( page => pager.next_page )
> %]">&gt;</a></li>
>        [% END %]
>        <li><a href="[% c.req.uri_with( page => pager.last_page )
> %]">&raquo;</a></li>
>    </ul>
> [% END %]
>
> Though my colleague rightly suggested we subclass Data::Page and
> perform the sliding window in there. This shows first page, previous
> page, the current page surrounded by near-by pages. Seems to do the
> job so far!

Hi,

I've just adopted your example and replaced my pager in InstantCRUD.
I added credit note like that:

=head1 AUTHOR

<Zbigniew Lukasiak>  C<< <<zz bb yy @ gmail.com>> >>
Pager adapted from example by Oliver Charles.


I hope you are satisfied.

Cheers,
Zbigniew

PS. Here is the adopted version:

[% IF pager %]
<div class="pager">
    <div class="counter">
        Page [% pager.current_page %] of [% pager.last_page %]
    </div>
    <div>
       [% IF pager.previous_page %]
           <span><a href="[% c.req.uri_with( page => pager.first_page
) %]">&laquo;</a></span>
           <span><a href="[% c.req.uri_with( page =>
pager.previous_page ) %]">&lt;</a></span>
       [% END %]

       [% start = (pager.current_page - 3) > 0 ? (pager.current_page - 3) : 1;
        FOREACH page IN [ start .. pager.last_page ] %]
           [% LAST IF loop.count > 6 %]
           [% IF pager.current_page == page %]
               <span class="current"> [% page %] </span>
           [% ELSE %]
               <span> <a href="[% c.req.uri_with( page => page )
%]">[% page %]</a> </span>
           [% END %]
       [% END %]

       [% IF pager.next_page %]
           <span><a href="[% c.req.uri_with( page => pager.next_page )
%]">&gt;</a></span>
           <span><a href="[% c.req.uri_with( page => pager.last_page )
%]">&raquo;</a></span>
       [% END %]
   </div>
</div>
[% END %]



More information about the Catalyst mailing list