qateam
qateam

Reputation: 11

Getting current page in CakePHP pagination

On one of my webpage, I show a list of customer details with default pagination [Paginator helper]. Each customer row has a corresponding 'edit' button which when clicked shows a DIV populated with that customer information. [This DIV has textboxes etc. where I can change customer info] After re-entering/modifying customer details, when I click on "Save" button, 2 ajax calls are made..

  1. First one to save the edited record
  2. The second one Updates the customer Listing on the same page with modified information

My problem : If I am on page 3 and edit one customer record, the 2nd ajax call refreshes the list but does not go to the page 3. It starts from page 1.

Please help.

Upvotes: 0

Views: 2841

Answers (4)

user1077915
user1077915

Reputation: 894

I use jquery / javascript to store the page on a cookie and then read it from the controller.

// -------------------------------------------------------------------------

// on action click remember current page

$('td.actions').click( function( event )
{
    var page = $('li.active a').html();
    var name = window.location.href.split('-').join('_').split('/').pop();

    $.cookie.raw = true;
    $.cookie( 'CakeCookie[' + name + '_page]', page, { expires: 365, path: '/' } );

});

Upvotes: 0

Gurudutt Sharma
Gurudutt Sharma

Reputation: 532

You can get your current page here:

$this->request->params['named']['page']

Upvotes: 1

Carlos Morales
Carlos Morales

Reputation: 5916

Did you try to use the link from Paginator? It maintains the page # to the controller.

Something like

// same parameters as $this->Html->link
<?php echo $this->Paginator->link( ... ) ?>

Check also the reference documentation for the Paginator Helper

Upvotes: 0

user1548335
user1548335

Reputation:

You can get your current page here:

<?php echo $this->Paginator->counter(array(
    'format' => ('{:page}')
      )); ?>

This is part of the solution. :)

Upvotes: 1

Related Questions