I was trying to list using pagination in Codeigniter. I was willing to use sorting in the list by using jquery ajax. It works perfectly for first page of pagination. I could do ascending and descending sorting in that page. But when i click on other page. It does not work.
What could be the problem. Can any one suggest me??
Thanks in advance.
This is the code for my controller
function listData(){
$this->clear_sample_id_catche();
$out=$this->Mgeneral->listData();
$per_page = 10;
$total = $this->Mgeneral->countData();
$data = $this->Mgeneral->listData($per_page, $this->uri->segment(3));
$base_url = site_url('general/listData');
$config['base_url'] = $base_url;
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = '3';
$this->pagination->initialize($config);
$data=array('body'=>'list','out'=>$data);
$this->load->view('template',$data);
}
This is for my model
function listData($limit = NULL, $offset = NULL)
{
$this->db->limit($limit, $offset);
$data=array();
$q=$this->db->get('tbl_sample_id');
if($q->num_rows()>0)
{ $data=$q->result_array();
return $data;
}
}
and i have use ajax as
<script type="text/javascript">
$(document).ready(function(){
$(“#internal”).click(function(){
$.ajax({url:"general/listData_internal_ascending",success:function(result){
$("body").html(result);
}});
});
});
Thank you
You function should look like this