Pagination again

Matts on 2003-07-09T08:03:06

OK, so it looked at first as though Data::Pageset would be what I wanted (thanks davorg and Ranguard!), and then it looked like it didn't quite give me what I needed...

The problem seemed to stem from a design decision in Data::Pageset - it was designed for explicitly paging through sets of data (via buttons to "page up" and "page down"), rather than what I wanted which was to do the paging a-la google, where it moves to the next pageset when you click on the last page in the list. i.e. in the below, clicking on 5 should move you to a set showing pages 5..10:

   <>
Whereas clicking on Prev/Next should take you to the next page, rather than the next pageset. This makes page flipping really easy (just hover the mouse over the "Next" button) and sensible.

Unfortunately Data::Pageset's boundaries are at distinct dividing points in the set, so you can't tell it to flip to the next/prev pageset when you get to the last number on a page. This seemed like a showstopper to me so I went on to do other things while I thought about it.

And then finally this morning the solution dawned on me. I could simply reduce the number of pages I expected to show, and subtract one and add one at the end to produce the effect I needed.

I ended up with the following code, which does what I need:
    if (my $n = $page->previous_page) {
        
            $n
            <<
        
    }
    if (my $n = $page->previous_set) {
        
            $n + $page->pages_per_set - 1
            $n + $page->pages_per_set - 1
        
    }
    foreach my $n ( @{ $page->pages_in_set } ) {
        
            
                $n == $page->current_page
            
            $n
            $n
        
    }
    if (my $n = $page->next_set) {
        
            $n
            $n
        
    }
    if (my $n = $page->next_page) {
        
            $n
            >>
        
    }
Now I'm going away to patch AxKit so that I can get rid of those HORRIBLE <xsp:attribute> tags - supporting attribute value templates a-la XSLT will make this significantly cleaner.