Featured Posts

Codeigniter Pagination Part 3 OK so we have now covered setting up Codeigniter Pagination and passing some simple data through it. We have also managed to add categories to our posts to make it a little...

Readmore

Codeigniter Pagination Part 2 So leading on from the last screencast we now have some simple data being pushed through the pagination library. Now were going to look at adding categorys to our posts...

Readmore

Codeigniter Pagination Part 1 One of the biggest things I see being asked around the codeigniter forums & IRC channel is pagination. So I have decided to create a set of tutorials from basic setup...

Readmore

Codeigniter Preparation Hopefully if I can keep my promise and will be rolling a set of screencast on this site and part of them will be to do with the Codeigniter Framework. I though it would...

Readmore

Radio Button Replacement With Style I thought I would kick off this blog with a short tutorial on how you can make form radio buttons look and feel allot more interesting. A recent job required the user to...

Readmore

Web Lee Rss

Codeigniter Pagination Part 4

Posted on : 12-06-2009 | In : Codeigniter, Jquery, Screencasts

36

Hopefully this will be a fun screencast for you. We will be using Jquery $.ajax GET request combined with the Codeigniter Pagination Library.

Im sure you will be suprised how easy this is achieved.

Screen Time: 16:42

Download example files here .

Other Usefull Links:

Comments (36)

Hey OES, very nice tutorial, but i have a simple question… How about if i want to send a friend of mine the url for the third page? I mean, how about make the paginition works like this

http://www.mywebsite.com/#3

So, someone can jump to 3 page without to open the first page and then clicks the 3 page link…

Cheers!!

Hi Harby.

The links will work like normal, so if you were to right click a pagination link and open in new window you will see the correct page. So copy link location and paste to your friend :-) .

I forgot to show in the screencast to turn off JS. You would have seen it works still the same.

Good Luck !

Thank you Lee :-)

Great work Lee!

I’ve been looking for tuts on how to use codeigniter and i’m dabbling with Jquery right now too. The pace you go through the casts are just right without leaving out anything important. I for one hope you continue to make them and appreciate your efforts.

Can I ask what you have planned for further tuts?

Regards,

Alan

Hi Alan,

Thank you for your kind words. I have a number of casts planned for the short future but not decided in which order yet! I think I will try and cover most of CI important libraries like Validaton, Upload, Database.

Make sure you follow on the RSS feed or Twitter.

If you would like something please ask :-) .

Lee,

Sounds like a good set of tuts i’ll look forward to seeing them :-) . I’ve been asked to create a site for a local football team and decided to go with CI. I’ve done some uploads as well as DB work with it so far, though i’m interested in the way you’d approach such things since i am quite inexperienced.

I know its been killed to death but i’d like to see your ideas behind a login system. Whether it be for single users or user groups, and how it can be used in the CI MVC architecture. Just an idea anyway.

Thanks again for all your work,

Alan

I’m curious about the ideas you’ve thought of to include history tracking in this? (i.e. support for forward/back)

Most common practice was to use #3 or #4 and pull the page number from the hash, since updating the hash wont cause the page to reload >_>

Well the URL string is built with Codeigniters Pagination. So depending on which URL segement is used we can use that number for the offset. Keeps URL strings alot cleaner :-)

Awesome stuff.

Screencast really helped me solve a bug in my pagination.

Thanks!

Hi Lee,
great tutorial! Can I ask you what tool are you using for debuging, it look like it could speed development (this thing with ‘Console’, ‘HTML’, ‘CSS’ buttons), may be it’s FF plug-in?

Been asked this one a few times now :-) .

a plugin called Firebug for Firefox. You can get it here..

the file in download link seem like for other tutorial

Which one ?

IS_AJAX is not working, i tried the following error comes

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant IS_AJAX – assumed ‘IS_AJAX’

Filename: controllers/news.php

Line Number: 39

lee check this for me please..
thx

Its because you have not followed the tutorial :-) .

Open up /application/config/constants.php and add the following.

define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

you will then be sorted.

Thanks its working great….u r da best

in pagination links, please how can i remove the digits,
first and last button? i want only next and previous to appear it that possible?

im sorry im very to all these, but thanks i found some1 like u.

thx

I would use CSS to hide them.

So make sure you use all the customizing options available (use config/pagination.php) and give them all a class ie hidden (css = display:none) to the ones you don’t want to display.

Hope that helps.

Thx lee for your answers, its really working fine. 1 last thing i want ask is, can i display eg. page 1 of 10, 2 of 10 and so on ?

Hey Lee…

These were great tutorials i have ever found on CI + MySQL + PHP + Jquery + Pagination :)
it was the best help for me n my team. i was struggling on net since 2 months n found n its gr8 to know tht my pagination is working completely fine. many thanks to your screencasts and your hard work.

I had one query, I have two pagination instances in single page. But its not working and overwrites pagination links. Can you just let me know is it a possible scenario?

Thanks,
Swetz

That ’s awesome, Lee. Thanks for that :)

Great Tutorial for ajax pagintion.

Thank a lot man, who create this video tutorial for us.

Great tutorial Lee. I already had pagination working then I implemented your ajax calls and it worked fine except i have this little problem. On the pagination, when i click on the second page the ajax calls the controller and it returns the correct set and the div refreshes, now when i click on the third page the ajax gets called twice and 2 same exact sets of results come back, then on the fourth page it gets called 4 times, going back to any page make the ajax call the number of previous calls to the power of 2 !!!! so you can imagine the controller being called 16 times on the 5th call!

I have a screenshot taken of firebug console as i go between the 2nd and 3rd page, you can see the number of request it’s making! the screenshot can be seen at http://www.nayzak.com/ajax_pag_debug.jpg

Any help would be appreciated.

Thanks again,
-Thomas

Thank you very much for this tutorial, I’m amazed how easy it is. I hope it works for me since I have implemented query strings and several parameters in the URL.

Thanks a lot for this excellent tutorial. You have removed a lot of fog from idea of mixing CI pagination and jQuery or Ajax.

Tom

great tut boss!!!!

Thanks, Lee

This is what i’m looking for

Here is another CI developer who wants to congratulate the author of this very very helpful article… Thanks again

That ’s awesome, Lee.. tanks..

i have problem..

can this method be used in CRUD process ??

how to use it?

Now I just want to say that this the best codeigniter tutorial site I have ever visited. I wait for the next best tutorial from start to finish, as usual.

Best thanks to you Lee . ^^ . Nice tutorial .

Hello, thanks for this great info. I work ajax reload like you.
GREAT SITE.
GREETINGS

I have learn a few good stuff here. Definitely price bookmarking
for revisiting. I wonder how so much effort you put to make the sort of wonderful informative web
site.

found other tutorial but this one is far more easier to understand, thank you!

Best Tutorials . i am very thankful to you.

Great tutorials, really helped. Thanks.

Write a comment