OldWest
OldWest

Reputation: 2385

CakePHP Ajax Pagination working BUT on every other sort ? - What am I doing wrong?

I set up some Ajax Pagination for sorting records. It's actually working as expected with the exception that:

1. On fresh page load: Click and sort column displays indicator and sorts as expected.

2. Sort again, and its processed as a standard http request. Results are sorted, but not by Ajax.

3. Sort a 3rd time, and the Ajax is back working and sorts as expected.

It's back and forth every other time Ajax, http, Ajax, http...

I cannot find out why it seems to be resetting every other sort click.

birds_controller.php

function index() {
    $birds = $this->paginate('Bird');
    $this->set(compact('birds', $birds));
}

index.ctp

<?php
$this->Paginator->options(array(
'update'      => '#birdTable',
'before'      => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer'    => false)),
'complete'    => $this->Js->get('#busy-indicator')->effect('fadeOut',   array('buffer' => false)),
));
echo $this->Html->image('indicator.gif', array('id' => 'busy-indicator', 'style' => '    display: none;'));
?>

<div id="birdTable">
...

Upvotes: 1

Views: 1423

Answers (2)

OldWest
OldWest

Reputation: 2385

I solved this, BUT I don't like this solution. It's on the lines of what I originally suspected. The buffer was not calling the correct data, and so I added:

echo $this->Js->writeBuffer();

to the index.ctp and now it works as expected. So I have a copy of the buffer still in my default as well for other scripts...

Does not seem right, but at least it works now.

Upvotes: 1

JJJ
JJJ

Reputation: 33163

The problem is probably that the links in the returned table are different than in the original: the original links are AJAX, when you click the paginator retrieves a new table with non-ajax links. Check with Firebug that the table structure is the same before and after click. If that doesn't help post more of your code, the pagination view is the relevant one here.

Also remember to do $this->helpers['Paginator'] = array('ajax' => 'Ajax'); as per http://book.cakephp.org/view/1234/AJAX-Pagination.

Upvotes: 0

Related Questions