0
votes

I am using cakephp 2.2.2 and I want to create a simple ajax pagination. I am following this ( http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#ajax-pagination ) and I cant seem to get it working right. When I load the page sometimes it uses ajax sometimes it doesnt, in IE 10 I also get something strange like the whole menu collapsing into div that was set to be updated.

Here is what I did:

  1. Put echo $this->Html->script('jquery'); inside the <head> of my layout file.
  2. Included RequestHandler component and Js helper in my controller.
  3. put this in the beginning of my view file:

    $this->Paginator->options(array( 'update' => '#content', 'evalScripts' => true ));

  4. put this in the bottom of layout file just before </body>: echo $this->Js->writeBuffer();

  5. Then i normally used paginator like this:

    echo $this->Paginator->sort('id');

Can somebody tell me if I am missing something or what is wrong because I really can't figure out what I'm doing wrong. Thanks very much.

2

2 Answers

2
votes

I also had same issues with ajax in pagination.

I found a temporary solution. In the controller function, add following code to set a flag variable.

 if($this->request->is('ajax')){
        $this->set('paginate',true);
    }

Then in the view, you need to hide the section other than under #content div.

<?php if(!isset($paginate)):
    // Code above # content div including the start of div
endif:?>

Pagination code inside the content div

<?php if(!isset($paginate)):
    // Code below # content div including content of div
endif:?>

P.S. The logic is that when pagination is done, other parts will not be shown in the paged view.

0
votes

Just move this code from your view file to your layout :

$this->Paginator->options(array( 'update' => '#content', 'evalScripts' => true ));