CodeIgniter Forums
AJAX Pagination with CI Pagination Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: AJAX Pagination with CI Pagination Library (/showthread.php?tid=6996)

Pages: 1 2 3


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
I have modified CI Pagination library into an ajax based pagination. Check here


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
Check the update. Open Wiki, find 'AJAX Pagination'


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]wiredesignz[/eluser]
You might want to throw some [ code ] tags into your submission Gin2, its quite difficult to read without them.


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
Oooppsss sorryyyy!! It'a done ( with !!! Thanks wireddesignz!


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Référencement Google[/eluser]
It's look like it's missing the informations about witch JS library should be used with your script or I misunderstood something ? Maybe a full real world using DB example should be nice too ?


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
Can this sample help you?
<b>CONTROLLER: my_data_page.php</b>
Code:
&lt;? class My_data_page extends Controller{
    function My_data_page(){
       parent::Controller();
       $this->load->library('table');
       $this->load->library('Ajax_pagination');
    }
    function index(){
        $data['makeColumns'] = $this->makeColumns();
        $data['getTotalData'] = $this->getTotalData();
        $data['perPage'] = $this->perPage();
        $this->load->view('my_data_page', $data);
    }
    //Pull 'name' field records from table 'contact'
    function getData(){
        
        $page = $this->input->post('page'); //Look at $config['postVar']
        if(!$page):
        $offset = 0;
        else:
        $offset = $page;
        endif;
        
        $sql = "SELECT name FROM contact LIMIT ".$offset.", ".$this->perPage();
        $q = $this->db->query($sql);
        return $q->result();
    }
    function getTotalData(){
      $sql = "SELECT * FROM people";
      $q = $this->db->query($sql);
      return $q->num_rows();
    }
    
    function perPage(){
         return 10; //define total records per page
      }
    
    //Generate table from array
    function makeColumns(){
         $contact = $this->getData();
         foreach($contact as $cont):
         $data[] = $cont->name;
         endforeach;
         return  $this->table->make_columns($data, 6); //6 colums maximum
    }
}
?&gt;
<b>VIEW: my_data_page.php</b>
Code:
<s\cript type="text/javascript" src="path-to-prototype.js"></s\cript>
<div id="content">
&lt;?
$config['first_link'] = 'First';
$config['div'] = 'content'; //Div tag id
$config['base_url'] = 'index.php/my_data_page';
$config['total_rows'] = $getTotalData;
$config['per_page'] = $perPage;
$config['postVar'] = 'page';

$this->ajax_pagination->initialize($config);
print $this->ajax_pagination->create_links();
//PRINT TABLE
print $this->table->generate($makeColumns);
?&gt;
</div>



AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Référencement Google[/eluser]
Yeah that's cool. But for the JS side, what I must do exactly ?
Do you have a sample snippet of code using Jquery or Scriptaculous ? (or any other web 2.0 JS lib)


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
<b>Addition: Initialize my_data_page in your page loader (i.e: my_page_data_loader.php)</b>
----------------------------------------
<b>CONTROLLER: my_data_page_loader.php</b>
Code:
&lt;? class My_data_page_loader extends Controller{
   My_data_page_loader(){
    parent::Controller;
  }
  function index(){
    $this->load->view('my_data_page_loader');
  }
}
<b>VIEW: my_data_page_loader.php</b>


Code:
<s\cript type="text/javascript" src="path/to/prototype.js"></s\cript>

<div id="content">your my_data_page will be displayed here</div>

<div id="response" style="display:none">ajax response</div>

<sc\ript type="text/javascrpt>">new Ajax.Updater('content','index.php/my_data_page',{onLoading:function(request){Element.show('response')}, onComplete:function(request){Element.hide('response')}, method: 'post', parameters:{nothing:'todo'}, evalScripts:true});</sc\ript



AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
before and after 'new Ajax.Updater ....' please insert javas\cript opening and closing tag;


AJAX Pagination with CI Pagination Library - El Forum - 03-19-2008

[eluser]Gin2[/eluser]
bye for now, it's morning in Indonesia. And, i have to sleep.. :-P