CodeIgniter Forums
Fixed number of links in pagination - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Fixed number of links in pagination (/showthread.php?tid=43234)



Fixed number of links in pagination - El Forum - 07-05-2011

[eluser]Constantin Iliescu[/eluser]
Hello!

I want to always have 10 link in pagination. Does anybody have an idea how I could accomplish this? As far as I can see in documentation, only the number of links from left and right of the current page can be set.

Thank you.


Fixed number of links in pagination - El Forum - 07-05-2011

[eluser]toopay[/eluser]
[quote author="cili" date="1309880395"]I want to always have 10 link in pagination. [/quote]

Then you need to manage pagination config for 'total_rows' and 'per_page'. Everytime you retrieve data from your database, you can use 'LIMIT' clause to limiting your database result into exact 10 * your 'per_page' config.


Fixed number of links in pagination - El Forum - 07-06-2011

[eluser]Constantin Iliescu[/eluser]
Hi, toopay,

Sorry, I haven't been too clear.

I'm trying to find if there's a way to specify the number of links shown at a time, similar to 'num_links' config.

So, instead of telling pagination to display "x" links to the left and right of the current page, can I tell it to always display "y" links?

Thank you.


Fixed number of links in pagination - El Forum - 07-06-2011

[eluser]osci[/eluser]
pagination library, as you see uses num_links config. There is no other setting for this behaviour. Either you extend pagination class to have this feature or you convert your 'y' links to num_links like
Code:
$config['num_links'] = (int)(y/2);
If your 'y' is even then it should work as you want otherwise because y % 2 = 1 you would get one link less, so in such a case maybe extending could be your only solution.


Fixed number of links in pagination - El Forum - 07-06-2011

[eluser]Constantin Iliescu[/eluser]
Thanks, osci.

The solution was, indeed, to extend the pagination class.