By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

without a page refresh sorting and pagination in codeigniter

P: 9
how it possible plz give me some code
Oct 7 '13 #1
Share this Question
Share on Google+
16 Replies


Dormilich
Expert Mod 5K+
P: 8,639
thatís not possible. CodeIgnitor is a PHP framework and PHP (a server(!)-side language) only works after you send a request from the browser to the server.

the only thing you could do is send a request via AJAX to CI to replace parts of the current page (though for CI thatís pretty much the same as if there were a reload).
Oct 7 '13 #2

P: 9
another way to possible like ajax,jquery etc...

i try ajax and successfully run code for pagination but i have not sorting successfully...i need sorting code

controller code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  class Contry extends CI_Controller
  3.  {   
  4.      function index($offset = 0)
  5.      {    
  6.         $this->load->library('pagination');
  7.         $limit = 8;
  8.         $this->load->model('Contry_model');
  9.         $totalRows = $this->Contry_model->getTotalPosts();
  10.         $data['posts'] = $this->Contry_model->getPosts($offset, $limit);
  11.  
  12.         $config['base_url'] = $this->config->item('base_url') . 'index.php/Contry/bloglist/';
  13.         $config['total_rows'] = $totalRows;
  14.         $config['per_page'] = $limit;
  15.  
  16.         $config['full_tag_open'] = '<div id="pagination">';
  17.         $config['full_tag_close'] = '</div>';
  18.         $this->pagination->initialize($config);
  19.  
  20.         $jsFunction['name'] = 'show';
  21.         $jsFunction['params'] = array();
  22.         $this->pagination->initialize_js_function($jsFunction);
  23.  
  24.         $data['base_url'] = $config['base_url'];
  25.         $data['page_link'] = $this->pagination->create_js_links();
  26.         //$this->load->view('header_view',$data);
  27.         $this->load->view('con_view', $data);
  28.         //$this->load->view('footer_view',$data);
  29.  
  30.      }
  31.  
  32.      function bloglist($offset = 0) 
  33.      {    
  34.         $this->load->library('pagination');
  35.         $limit = 8;
  36.         $this->load->model('Contry_model');
  37.         $totalRows = $this->Contry_model->getTotalPosts();
  38.         $data['posts'] = $this->Contry_model->getPosts($offset, $limit);
  39.  
  40.         $config['base_url'] = $this->config->item('base_url') . 'index.php/Contry/bloglist/';
  41.         $config['total_rows'] = $totalRows;
  42.         $config['per_page'] = $limit;
  43.         $config['full_tag_open'] = '<div id="pagination">';
  44.         $config['full_tag_close'] = '</div>';
  45.         $this->pagination->initialize($config);
  46.  
  47.         $jsFunction['name'] = 'show';
  48.         $jsFunction['params'] = array();
  49.         $this->pagination->initialize_js_function($jsFunction);
  50.  
  51.         $data['base_url'] = $config['base_url'];
  52.         $data['page_link'] = $this->pagination->create_js_links();
  53.         //$this->load->view('header_view',$data);
  54.         $this->load->view('data_view', $data);
  55.         //$this->load->view('footer_view',$data);
  56.  
  57.      }
  58.      function con_delete($id)
  59.      {        
  60.              //$this->load->helper('URL')
  61.             $this->load->library('table');
  62.             $this->load->helper('html');
  63.             $this->load->model('contry_model');
  64.             if((int)$id > 0)
  65.             {    
  66.                 $this->contry_model->mod_delete($id);
  67.             }
  68.             //redirect('http://localhost/Codeigniter/index.php/contry/');
  69.         }    
  70.  
  71.  }
  72. ?>
model code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class Contry_model extends CI_Model
  3. {
  4.     function getTotalPosts()
  5.     {    
  6.          $this->load->database();
  7.           //$this->db->order_by("id", "desc"); 
  8.          $query = $this->db->query("SELECT count(*) as total_rows FROM register_page");
  9.  
  10.          if ($query->num_rows() > 0) {
  11.             $row = $query->row();
  12.             return $row->total_rows;
  13.         }
  14.         return 0;
  15.     }
  16.     function getPosts($offset, $limit)
  17.     {
  18.          $this->load->database();
  19.          //$query = $this->db->query("SELECT * FROM register_page order by id asc LIMIT $offset, $limit");
  20.          $query=$this->db->query("select * from register_page LIMIT $offset, $limit");
  21.          if ($query->num_rows() > 0)
  22.          {
  23.             return $query->result();
  24.          }
  25.     }
  26.     function mod_delete($id)
  27.     {
  28.         $this->load->database();
  29.         $this->db->delete('register_page',array('id'=>$id));
  30.     }
  31.  
  32. }
  33. ?>

ajax code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Ajax try</title>
  4.     </head>
  5.     <body>
  6.         <script type="text/javascript">
  7.             function show(offset)
  8.             {
  9.                 //alert("<?php //echo "Next Data";?>"+offset);
  10.                 if (window.XMLHttpRequest)
  11.                 {
  12.                     xmlhttp=new XMLHttpRequest();
  13.                 }
  14.                 else
  15.                 {
  16.                     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  17.                 }
  18.                 xmlhttp.onreadystatechange=function()
  19.                 {
  20.                     if (xmlhttp.readyState==4 && xmlhttp.status==200)
  21.                     {
  22.                         document.getElementById("data_view").innerHTML=xmlhttp.responseText;
  23.                     }
  24.                 }
  25.                 xmlhttp.open("GET","<?php echo $base_url;?>" + offset,true);
  26.                 xmlhttp.send();
  27.  
  28.             }
  29.         </script>    
  30.         <script>
  31.  
  32.         </script>    
  33.         <div id="data_view">
  34.             <?php
  35.             $data['posts'] = $posts;
  36.             $data['page_link'] = $page_link;
  37.             $this->load->view('data_view', $data);
  38.             ?>
  39.         </div>
  40.     </body>
  41. </html>
  42.  
  43. view code
  44.  
  45. <html>
  46. <head>
  47.  
  48. </head>
  49. <center>
  50. <body bgcolor="#FF9933">
  51. <br/><br/>
  52. <table class="sortable" border="1px">
  53. <tbody>
  54.     <tr>
  55.         <th align="center">Id</th>
  56.         <th align="center">FristName</th>
  57.         <th align="center">LastName</th>
  58.         <th align="center">E-Mail</th>
  59.         <th align="center">RE-Mail</th>
  60.         <th align="center">Password</th>
  61.         <th align="center" colspan="2">Action</th>
  62.     </tr>
  63.     </thead>
  64.  
  65.     <?php foreach($posts as $post):?>
  66.     <tr>
  67.         <td align="center"><?php echo $post->id; ?></td>
  68.         <td align="center"><?php echo $post->firstname; ?></td>
  69.         <td align="center"><?php echo $post->lastname; ?></td>
  70.         <td align="center"><?php echo $post->email; ?></td>
  71.         <td align="center"><?php echo $post->remail; ?></td>
  72.         <td align="center"><?php echo $post->password; ?></td>
  73.  
  74.         <td><a href="http://localhost/Codeigniter/index.php/contry/con_delete/<?php echo $post->id;?>">Delete</a></td>
  75.     </tr>
  76.     <?php endforeach;?>
  77.  
  78. </table> 
  79. <br/><br/>
  80. <?php echo $page_link; ?>
  81. </body>
  82. </center>
  83. </html>
Oct 7 '13 #3

P: 9
give me a some hints....
Oct 9 '13 #4

Dormilich
Expert Mod 5K+
P: 8,639
regarding the sorting, do you want to sort server-side (then you need to sort via SQL) or client-side (then you can use an appropriate JS framework)?
Oct 9 '13 #5

P: 9
i have use only ajax....give me some example link.....
use ajax sorting possible then give me some hints....
Oct 9 '13 #6

Dormilich
Expert Mod 5K+
P: 8,639
AJAX and sorting is not related at all.

and it’s still in question what you want to sort.
Oct 9 '13 #7

P: 9
id,firstname,lastname, i have acending and descending sorting without page refresh
Oct 9 '13 #8

Dormilich
Expert Mod 5K+
P: 8,639
so I can safely assume that you want to sort the displayed data only, not all data in the DB?
Oct 9 '13 #9

P: 9
yas i want to sort only display data.....then after click 2 page that time sort another data...
Oct 9 '13 #10

Dormilich
Expert Mod 5K+
P: 8,639
there are some sorting plugins out there, e.g. http://tablesorter.com/docs/
Oct 9 '13 #11

P: 9
sory but i have frist time codeigniter use so i have many problem....

that example only sort table but i have sort database value...

give me another without page refresh database value sorting demo
Oct 10 '13 #12

Dormilich
Expert Mod 5K+
P: 8,639
that example only sort table but i have sort database value...
some posts ago you said you don’t want to sort raw DB data.
Oct 10 '13 #13

P: 9
i have use pagination and all data fetch my db and pagination time my disply data limit 8 row....
that time i have sort only that 8 data sort without page refresh.......
Oct 10 '13 #14

Dormilich
Expert Mod 5K+
P: 8,639
that time i have sort only that 8 data sort without page refresh.......
then the link above is fine.
Oct 10 '13 #15

P: 9
plz give me soluation fastly.....beacuse that question ask my interview...
Oct 10 '13 #16

Dormilich
Expert Mod 5K+
P: 8,639
I’m not a CI expert.
Oct 10 '13 #17

Post your reply

Sign in to post your reply or Sign up for a free account.