[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:
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'>
<?=$pagination?>
<?php foreach($posts AS $post):?>
<p><?=$post->title?><p>
<?php endforeach?>
</div><!--End of display-content-->
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
(sorry for my bad english)