Randell's Tech Blog |
CodeIgniter: AJAX Pagination, part 2 Posted: 26 Jun 2009 09:13 AM PDT It seems that I forgot to include an example of how to use the MY_Pagination class in my previous post regarding AJAX Pagination on CodeIgniter using jQuery, so here it is. The first function displays the first page: function index() { $this->load->model('Transaction_model'); $this->load->library('pagination'); $config['base_url'] = site_url('transactions/page/'); $config['total_rows'] = $this->Transaction_model->count_all(); $config['per_page'] = '20'; $this->pagination->initialize($config); $this->load->vars( array( 'transactions' => $this->Transaction_model->get_all($config['per_page']), 'pagination_links' => $this->pagination->create_ajax_links('transactions_all') ) ); $this->template->render('home/transactions_all'); } You’ll see that we load the library similar to how we load the original Pagination class. Note that you're NOT supposed to include the prefix. Just assume that there is a You’ll notice several differences from the normal use of the Pagination class:
Second function: function page($offset = 0) { $this->load->model('Transaction_model'); $this->load->library('pagination'); $config['base_url'] = site_url('transactions/page/'); $config['total_rows'] = $this->Transaction_model->count_all(); $config['per_page'] = '20'; $this->pagination->initialize($config); $this->load->vars( array( 'transactions' => $this->Transaction_model->get_all($config['per_page'], $offset), 'pagination_links' => $this->pagination->create_ajax_links('transactions_all') ) ); $this->load->view('home/transactions_page'); } You’ll notice that the second function is almost similar to the the first except for the following:
The views: <div id="transactions_all"> <?php echo $this->load->view('home/transactions_page'); ?> </div> And here is the code for <?php if (count($transactions)): ?> <table><tbody> <tr> <th>Date</th> <th>Details</th> <th>Amount</th> </tr> <?php foreach($transactions as $key => $transaction): ?> <tr> <td><?php echo $transaction->transaction_stamp; ?></td> <td><?php echo $transaction->transaction_details; ?></td> <td><?php echo $transaction->transaction_amount; ?></td> </tr> <?php endforeach; ?> <tr> <td colspan="3"><?php echo $pagination_links; ?></td> </tr> </tbody></table> <?php else: ?> No transactions found. <?php endif; ?> Lastly, you might be wondering what in the world is the Related posts: Tags: Ajax, CodeIgniter, jQuery, Pagination |
You are subscribed to email updates from Randell's Tech Blog To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Inbox too full? ![]() | |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
0 comments:
Post a Comment