Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Cakephp ajax pagination using jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 844
    Comment on it

    Using default pagination helper in cakephp.

    <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')); ?>
    </div>
    

    Below is the javascript code.

    <script>
        $(document).ready(function(){
            $(".paginator a").click(function(){
                $("#updated_div_id").load(this.href);
                return false;
            })
        });
    </script>
    

    Once you click on a link under that div, it fetch the url (this.herf) and calling page using ajax.

    For example your controller calling ajax_pages action.

    function ajax_pages(){
            $this->layout = 'ajax';
            $this->paginate = array(
                                    'order' => array('Module.created_date' => 'desc'), 
                                    'recursive' => -1,
                                    "limit" => PAGINATION_LIMIT
                                    );
    
            $conditions['Module.module_type'] = $module_type;
            $data = $this->paginate("Module", $conditions);
            $this->set(compact("data"));  
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: