Coding Cheatsheets - Learn web development code and tutorials for Software developers which will helps you in project. Get help on JavaScript, PHP, XML, and more.

Post Page Advertisement [Top]

Cakephp Ajax Pagination

Cakephp Ajax pagination works same like normal pagination , the difference is that it load the pages without refreshing

Controller index function

public function index(){
        $this->paginate = array('limit'=>5,'order'=>' desc');  
$userDetail = $this->paginate('User');
if($this->RequestHandler->isAjax()){ // check the type of request
$this->layout = '';
$this->autoRender = false;
$this->render('index');  // render the same view

User index view

// script to load page by ajax
$(".pagination a, .header a").on('click',function(){
return false;

<div id="content">
// show the content
<?php foreach($userDetail as $admins){?>
<td><?php echo $admins['User']['name'];?></td>
<td><?php echo $admins['User']['email'];?></td>
<td><?php echo $admins['User']['message'];?></td>
<?php } ?>

// pagination helper
<div class="pagination">
<?php echo $this->Paginator->prev('Prev');?>
<?php echo $this->Paginator->numbers(array('separator' => false));?>                  
<?php echo $this->Paginator->next('Next');?>

No comments:

Post a Comment

Bottom Ad [Post Page]