Part of the EllisLab Network
   
 
new Jquery pagination with CI?
Posted: 06 October 2008 08:58 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  88
Joined  10-15-2007

hello everyone

i want to use ajax pagination with CI, and i saw those files in here:
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/

i tried to work with it, but i didn’t get any result.
does anyone can help me how to use those files, or give me maybe an idea of how to make this jQuery pagination?

thank u!

Profile
 
 
Posted: 06 October 2008 09:29 AM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4839
Joined  07-14-2006

The simplest way to create ajax pagination is to make a controller method that gets the data that needs to be displayed and a view where the data is shown. in the view where the data is shown there are also all the links to the pages. And then it’s simply a matter of displaying the first data when the page is shown for the first time and by clicking on the links the other data parts are retrieved.

If you are smart you make the links to work in php and manipulate the link in javascript to only retrieve the data. For example you can prefix the last non numeric segment with ajax_ to retrieve the data so you can have show/20 which load the page in rows beginning with the 20th and ajax_show/20 gets you only the data. For this you need a model method that gets the data parts and two controller methods.

Profile
 
 
Posted: 06 October 2008 09:38 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  88
Joined  10-15-2007
xwero - 06 October 2008 09:29 AM

The simplest way to create ajax pagination is to make a controller method that gets the data that needs to be displayed and a view where the data is shown. in the view where the data is shown there are also all the links to the pages. And then it’s simply a matter of displaying the first data when the page is shown for the first time and by clicking on the links the other data parts are retrieved.

If you are smart you make the links to work in php and manipulate the link in javascript to only retrieve the data. For example you can prefix the last non numeric segment with ajax_ to retrieve the data so you can have show/20 which load the page in rows beginning with the 20th and ajax_show/20 gets you only the data. For this you need a model method that gets the data parts and two controller methods.

i think i am too newbie to ajax and jquery cuz i didn’t understand anything of what u said… =[

i am now trying to modify some jQuery codes to get the picture of it, but it’s hardddd

Profile
 
 
Posted: 07 October 2008 01:36 AM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4839
Joined  07-14-2006

Ok here is the basic code. I’m not 100% sure it works but you can debug if you want wink

// controller
function page($offset = 0)
{
      $this
->load->model('model');
      
$this->load->library('pagination');

      
$config['base_url'] = 'http://example.com/index.php/test/page/';
      
$config['total_rows'] = $this->model->num_rows();
      
$limit = 20;
      
$config['per_page'] = $limit;
      
$config['num_links'] = 10000; // ridiculous high number to show all the links
      
$config['full_tag_open'] = '<p id="pagination">';
      
$config['full_tag_close'] = '</p>';

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

      
$data['pagination'] $this->pagination->create_links();
      
      
$this->load->library('table');
      
      
$data['table'] = $this->table->generate($this->model->content($limit,$offset));

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

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

   echo
$this->table->generate($this->model->content($limit,$offset));
}
// javascript
$(function(){
  
// change page to ajax_page in pagination urls
  
$('#pagination a').each(function(){
    
var href = $(this).attr('href');
    
href = href.replace(/page/,'ajax_page');
    $(
this).attr('href',href);
  
});
  
// ajax request
  
$('#pagination a').click(function(){
    
$.ajax({
       type
: "GET",
       
url: $(this).attr('href'),
       
success: function(table){
          
$('table').remove(); // remove content
          
$('#pagination').after(table); // add content
       
}
    }
);

    return
false; // don't let the link reload the page
  
});
});
// view : page.php
<?php echo $pagination.$content ?>
Profile
 
 
Posted: 07 October 2008 02:13 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  32
Joined  06-30-2008

@A.M.F   Sorry i have not seen this post until i saw a referrer in my blog .

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

Here is a small example/guideline i have created modifying the code of xwero. Hope this comes helpful.

@xwero… thanks for your example.

 Signature 

My Blog: tohin.wordpress.com

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 115027 Total Logged-in Users: 63
Total Topics: 122466 Total Anonymous Users: 3
Total Replies: 647382 Total Guests: 466
Total Posts: 769848    
Members ( View Memberlist )