Welcome Guest, Not a member yet? Register   Sign In
Customize Pagination class
#1

[eluser]web_developer[/eluser]
Hello,

I want to customize Pagination class.

I have to show page link in range.. ($config['total_rows'])

For exmple like below

|<< << 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 >> >>|

if User go to page number 11 then link should be display 11 - 20

(In short need to display links in range)

1 - 10
11 - 20
21 - 30 and so on...

So for that what change required to do?
#2

[eluser]CoolGoose[/eluser]
You can change set the num_links setting to have a different value.
Code:
$this->load->library('pagination');

$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '200';
$config['per_page'] = '20';
$config['num_links'] = 5;

$this->pagination->initialize($config);
echo $this->pagination->create_links();

/le
Ah, damn. I just noticed that you want the First Link from that Listing to be the first one.

/le 2
Create your own library based on CI's one and fiddle with
Code:
$start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
#3

[eluser]CoolGoose[/eluser]
I think I nailed it:

Code:
// Calculate the start and end numbers. These determine
// which number to start and end the digit links with
$start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
$end   = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;

if ($this->cur_page >= 10)
{
  $base_number_raw = substr($this->cur_page, 0, -1);
  $base_number = $base_number_raw * 10;
  
  $start = $base_number_raw;
  $end   = $base_number_raw + $this->num_links;
}
else
{
  $start = 1;
  $end   = $this->num_links;
}

Not really tested Tongue.
#4

[eluser]web_developer[/eluser]
Ok got it..

So for that I have to use my own logic,

Such type of functionality will not work in Pagination defaault library...

I was thinking that if this can manage with pagination library then it would become good.

But any way Now I will create my own pagination for that. Smile

Thanks for helping..
#5

[eluser]CoolGoose[/eluser]
Just try with that bit of code before you create one from scratch.
So copy the whole pagination class, rename the class to something else like WD_pagination, save it as wd_pagination.php into your library directory and replace the $start / $end part from it with what I wrote above.

In any case, keep us informed about your progress Smile.




Theme © iAndrew 2016 - Forum software by © MyBB