Category Covered

cakephp ajax pagination using jquery

If you want paginate data in cakephp using jquery then just follow the step. Suppose you are in index.ctp page and already your pagination is working as cakephp format. Now replace your pagination div with the following code.







<div class="paginator">
        <?php echo $paginator->first(' First ', null, null, array('class' => 'disabled')); ?>
        <?php echo $paginator->prev('Previous ', null, null, array('class' => 'disabled')); ?>
        <?php echo $paginator->numbers(); ?>
       <?php echo $paginator->next(' Next ', null, null, array('class' => 'disabled')); ?>
        <?php echo $paginator->last(' Last ', null, null, array('class' => 'disabled')); ?>
On the same view page use the following jquery script. And make sure you have already include your jquery script.

        $(".paginator a").click(function(){
            return false;

Here is your controller for that view.
function index(){
        $this->layout = 'ajax';
 //Make a blank layout inside your cakephp layout folder like ajax.ctp
        $this->paginate = array(
                                'order' => array(' => 'desc'),
                                'recursive' => -1,
                                "limit" => 20
        $conditions['] = $something; // this is not necessary
        $data = $this->paginate("MyModule", $conditions);

Comments on "cakephp ajax pagination using jquery"
Comment by, Sandeep dhiman

Hi , Is this really a ajax pagination have you tested atleast once .This is default paginatin of cake php that we cake provides us.Please check once and tell me how can i use ajax pagination in cake php
Comment by, Mahfoozur Rahman

Hey Shandeep! It really works. Could you please specify where are you facing problem implementing this tutorial..
Related posts