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
    • 938
    Comment on it

    Using default pagination helper in cakephp.

    1. <div class="paginator">
    2. <?php echo $paginator->first(' First ', null, null, array('class' => 'disabled')); ?>
    3. <?php echo $paginator->prev('Previous ', null, null, array('class' => 'disabled')); ?>
    4. <?php echo $paginator->numbers(); ?>
    5. <?php echo $paginator->next(' Next ', null, null, array('class' => 'disabled')); ?>
    6. <?php echo $paginator->last(' Last ', null, null, array('class' => 'disabled')); ?>
    7. </div>

    Below is the javascript code.

    1. <script>
    2. $(document).ready(function(){
    3. $(".paginator a").click(function(){
    4. $("#updated_div_id").load(this.href);
    5. return false;
    6. })
    7. });
    8. </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.

    1. function ajax_pages(){
    2. $this->layout = 'ajax';
    3. $this->paginate = array(
    4. 'order' => array('Module.created_date' => 'desc'),
    5. 'recursive' => -1,
    6. "limit" => PAGINATION_LIMIT
    7. );
    8.  
    9. $conditions['Module.module_type'] = $module_type;
    10. $data = $this->paginate("Module", $conditions);
    11. $this->set(compact("data"));
    12. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: