CodeIgniter AJAX Pagination Example/Guideline

[ Update:  Download the example and source file from download page. ]

I wanted to put this example a long time ago ..  Here is a small example (thanks to xwero; i took his code from here  :D . I wanted to create a full application example but now i think it’s better to show this one. It’s not a tested code rather than a small guideline.

 

 

 

 

class Test extends Controller {

	function page($offset = 0)
	{
		ob_start();
		$this->ajax_page( 0 );
		$initial_content = ob_get_contents();
		ob_end_clean();	

		$data['table'] = "<div id='content'>" . $initial_content . "</div>" ;

	    $this->load->view('page',$data);

	}

	function ajax_page($offset = 0)
	{
	  	$this->load->model('model');
		$this->load->library('Jquery_pagination');

		$config['base_url'] = site_url('test/ajax_page/');
		/* Here i am indicating to the url from where the pagination links and the table section will be fetched */

		$config['div'] = '#content';
		/* CSS selector  for the AJAX content */

		$config['total_rows'] = $this->model->num_rows();
	    $config['per_page'] = 20;

	    $this->jquery_pagination->initialize($config);

	    $this->load->library('table');

	    $html =  $this->jquery_pagination->create_links() . br(1)
				.  $this->table->generate($this->model->content( $limit, $offset));

		echo $html;
	}
}

 

 

 

 

Note: Don’t forget to add the jquery.js in your view file, Jquery_pagination.php in your library folder.

15 Comments »

  1. cvv said

    vg

  2. cvv said

    dcc

  3. sagive said

    The url of the full code wont load ..
    http://codeigniter.com/forums/viewthread/93045/ <– this one

    Is it the right one?

  4. tohin said

    full code ?? .. :( .. more words plz .

  5. mrcoder said

    am trying to implement ajax pagination in ci. ihave followed the steps as per the tutuoril.

    http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/

    I am getting the pagination links but when iam clicking the link data is not changing.ie pagination is not working can any one help me.

  6. tohin said

    Have u included Jquery ? if you have included and still not working .. check with firebug ..

  7. mithil said

    I cant understand how to use your code example. Please help how to setup.
    i have downloaded these files civalidate.rar,component_library.rar,Jquery_pagination_20081201.rar, jquery_pagination_example_20081201.rar, Rabbitform.rar, screencast.rar, i am beginner in CodeIgniter

  8. mrcoder said

    Codeigniter Jquery Ajax Pagination

    This is the view iam having

  9. mrcoder said

    Codeigniter Jquery Ajax Pagination

  10. mrcoder said

    i have inclued the jquery-1.2.6.js in the view file

  11. tohin said

    as you are in beginner level start with my slide “Introduction to CodeIgniter” in my slideshare account. Later step by step you will understand how those examples work.

  12. tohin said

    i can’t see your view files so better put your code in http://www.etherpad.com and tweet me the link .. i will take a look @ it.

  13. bp said

    Where are the source file? I would like to see the model where $this->model->contents returns.

    thanks,

  14. tohin said

    hmm.. actually this was just a guideline not a full functional code.. you can check the link i have added from where i took the code for showing this guideline.

    A hint:
    $this->model->num_rows() should sent total number of rows..
    and $this->model->content($limit, $offset) should sent a resultset ..

    I hope this helps

  15. Nice Example

RSS feed for comments on this post · TrackBack URI

Leave a Comment