CodeIgniter Forums
Simple Ajax paging with existing pagination lib & jQuery - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Simple Ajax paging with existing pagination lib & jQuery (/thread-20443.html)

Pages: 1 2


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 07-10-2009

[eluser]Berserk[/eluser]
Step 1: edit existing pagination lib:

a. Find:
Code:
var $query_string_segment = 'per_page';


Add below:

Code:
var $is_ajax_paging        = FALSE;
    var $paging_function       = 'ajax_paging'; // your jquery paging function

b. Find:
Code:
if ($num_pages == 1)
        {
            return '';
        }

Add below:

Code:
if($this->is_ajax_paging == TRUE)
        {
            $paging_function = 'onclick="javas+cript:'.$paging_function.'();return false;"';
        }
        else{
            $paging_function = '';
        }


c. add '.$paging_function.' on all of a element you found in Pagination.php

ex:
Code:
<a  >
should be
Code:
<a+'.$paging_function.'> //remove plus



Step 2: config your paging in controller (similar with default paging config):

if you want to use ajax paging just add

Quote:$config['is_ajax_paging'] = TRUE; //default FALSE

if don't, set it to FALSE
Ex:

Code:
// Set pagination    
    $config['base_url']        = site_url('my/controller/');        
    $config['total_rows']      = 1000;
    $config['uri_segment']     = 3;
    $config['per_page']        = '10';
    $config['is_ajax_paging']      =  TRUE; // default FALSE
    $config['paging_function'] = 'ajax_paging' // Your jQuery paging
    $this->pagination->initialize($config);
            
    $data['pagination'] = $this->pagination->create_links();
$data['posts'] = $this->my_model->get_all_posts($this->pagination->per_page, $this->uri->segment(3))
;

Step 3: Set your view:

Exp:
Code:
<div id = 'display-content'>
&lt;?=$pagination?&gt;
&lt;?php foreach($posts AS $post):?&gt;
<p>&lt;?=$post->title?&gt;<p>
&lt;?php endforeach?&gt;


</div>&lt;!--End of display-content--&gt;




Step4 : create jQuery paging function
Code:
ajax_paging = function(){
    $("p.pagination a").click(function() {              
               $.ajax({
                 type: "GET",
                 url: $(this).get(),
                 success: function(html){
         $("#display-content").html(html);
                  }
               });              
             });            
       return false;
     };


Finish!

---------------------

You can use both non-ajax paging and ajax paging at same time, no need to rewrite your code (just need change $config['is_ajax_paging'] to TRUE or FALSE ). Hope it will help Smile (sorry for my bad english)


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 07-10-2009

[eluser]Unknown[/eluser]
any demos?


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 07-10-2009

[eluser]mrliam69[/eluser]
So does
Code:
<a+ href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;

become (without the plus after the a)

Code:
<a+ '.$paging_function.' href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;



Simple Ajax paging with existing pagination lib & jQuery - El Forum - 07-11-2009

[eluser]Berserk[/eluser]
@kurt: sorry, have no demo now Smile
@mrliam69: thanks Smile


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 08-26-2009

[eluser]sihijau[/eluser]
could you give me demo and download files with instruction, please?
i'm newbie


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 08-26-2009

[eluser]sihijau[/eluser]
could u give me demo and download files, please?
i'm a newbie.
thanks


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 10-30-2009

[eluser]jiahui[/eluser]
hello,

I followed exactly the explanation as Berserk described and applied it into my project.

But I get this error msg: Parse error: syntax error, unexpected T_VARIABLE ....

What is the problem on this line:
Code:
$this->pagination->initialize($config);
?

Below is the scripting which I added into controller:

Code:
// Set pagination    
        $config['base_url']        = site_url('accounts/');        
        $config['total_rows']      = 1000;
        $config['uri_segment']     = 3;
        $config['per_page']        = '10';
        $config['is_ajax_paging']      =  TRUE; // default FALSE
        $config['paging_function'] = 'ajax_paging' // Your jQuery paging
        
        $this->pagination->initialize($config);
                
        $data['pagination'] = $this->pagination->create_links();
        
        $data['accounts'] = $this->usercontacts_model->get_admin_contacts($this->pagination->per_page, $this->uri->segment(3))



Simple Ajax paging with existing pagination lib & jQuery - El Forum - 11-05-2009

[eluser]charlie spider[/eluser]
you forgot the semicolon ; after config['paging_function'] = 'ajax_paging'

but you've probably figured that out by now.


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 11-07-2009

[eluser]Amzad Hossain[/eluser]
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/
http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/


Simple Ajax paging with existing pagination lib & jQuery - El Forum - 12-01-2009

[eluser]ngocthai[/eluser]
very good, thanks for share