Welcome Guest, Not a member yet? Register   Sign In
Always show Prev and Next link
#1

[eluser]xzela[/eluser]
Hi all.

I've got a particular problem I'm hoping someone might be able to help with. I'm using the Pagination Library to create a simple paging control on one of my pages.

The problem I'm trying to solve is that I want to 'Prev' and 'Next' links to show up, even if the user is at the beginning or end of the result list. Ideally, if the user is at the beginning of the result set, the 'Prev' link would be visible but not 'clickable'.

I've gone over the Pagination Library documents and didn't find anything that specifically addresses this functionality.

Anyway, if anyone has any insight, I'd love to hear it.

Thanks.
#2

[eluser]SPeed_FANat1c[/eluser]
Try manually check if you're on first or on the last page and then add some html that shows 'prev' or 'next' not clickable links.
Probably you'll need javasript for adding html
#3

[eluser]clip[/eluser]
I don't think this is possible with the default functionality of the Pagination Library. Extending this library is probably the cleanest way to accomplish what you need.
#4

[eluser]xzela[/eluser]
yeah, i figured that was the case.

I'm always hesitant to modify the core.

You never know what you might damage with the changes.
#5

[eluser]clip[/eluser]
No damages: just create a MY_Pagination library drop it in your application/libraries folder with your custom method. I would copy the method(s) that handle the link stuff paste them into your MY_Pagination library then modify the methods there. When your application initializes, it will overide the methods in the Core library with the ones in your custom library.

So your MY_Pagination.php library would look something like this:

Code:
class MY_Pagination extends CI_Pagination {
    
   function __construct()
   {
       //code here......
   }
  
   function some_method()
   {
      //code here......
   }


}
#6

[eluser]Derek Allard[/eluser]
I needed this recently myself. Start by grabbing a new copy of the pagination library from the repo. I added in a few new things, and its worth starting from that code.

From there, you'll need
Code:
// Render the "previous" link
if  ($this->prev_link !== FALSE AND $this->cur_page != 1)
{
    $i = $uri_page_number - $this->per_page;
                        
    if ($i == 0 && $this->first_url != '')
    {
        $output .= $this->prev_tag_open.'&lt;a anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;                
    }
    else
    {
        $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix;
        $output .= $this->prev_tag_open.'&lt;a anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
    }
}
else
{
    $output .= $this->prev_tag_open.'<span class="button button_inactive">'.$this->prev_link.'</span>'.$this->prev_tag_close;
}
and
Code:
// Render the "next" link
if ($this->next_link !== FALSE AND $this->cur_page < $num_pages)
{
    $output .= $this->next_tag_open.'&lt;a anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page * $this->per_page).$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
}
else
{
    $output .= $this->next_tag_open.'<span class="button button_inactive">'.$this->next_link.'</span>'.$this->next_tag_close;
}

Obviously, the markup in the "else" portion of each statement is up to you. If I could think of a way to make that output standardized enough that everyone would find it useful, I'd roll it into the main library.
#7

[eluser]PhireGuys[/eluser]
lol wish I read this before. Didn't take me too long but I needed to do the same thing and just went through the code until I found this area.




Theme © iAndrew 2016 - Forum software by © MyBB