I am using the CakePHP's inbuilt pagination method in my view forms page so that only five forms are displayed in a page. I get a few problems in the page navigations.Before I list my problems, I'll describe my view page so that you get a better idea of what I'm trying to do.
In my view page, I have three tabs,namely, 'All','Drafted' and 'Submitted'. The page normally displays all the Forms in the 'All' tab initially. If I click the 'Submitted' or 'Drafted' tab, only the submitted or drafted forms are displayed respectively.
Now the problems I get are:
Suppose I am in the All tab initially,I view the forms in page No:1 and then click Page Number:2 and view the forms in page 2. But then if I click the other tabs, 'Drafted' or 'Submitted' ,I get to see the second page in those sections. But actually if I click the other tabs, I should view only the Page:1 of it,right?
Suppose I am in the other tabs, 'Drafted' or 'Submitted' and have clicked Page:2 of it. Then when I click back Page:1, it shows the Page:1 of 'All' tabs section. But I need the Page:1 of the section I have clicked.
Actually I have given the page limit as 5. In the 'All' tabs section I have 6 forms,so 5 are displayed in the first page and the last one in the second page. But when I click submitted tab, where I have 4 forms, only 3 are displayed in the first page and last one in the second page. Since pag. limit is 5, I should get all the 4 forms in the first page itself right? why only 3 are displayed?
I think my question is too lengthy,but please some one be patient eough to help me out.. I'll also add the code here ..
This is the code in my controller:
var $paginate = array(
'limit' => 5,
'order' => array(
'Form.created' => 'desc'
)
);
function view()
{
$this->set('forms',$this->paginate('Form',array('Form.created_by'=>$userId)));
}
And I add the page navigation to my view file:
<?php echo $paginator->numbers(); ?>
EDIT
Actually, when I click the tab links, I do not move to other pages. I stay in the same page but display different results using JQuery and PHP code.
So only a hash gets added in the url when I click 'Drafts' or 'Submitted' link.
The code which changes the page is:
$(document).ready(function(){
function all(){
<?php foreach($myForms as $form):?>
$('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).show();
<?php endforeach;?>
$('#sort_by').find(".selected").removeClass();
$('#All').addClass("selected");
}
function drafted(){
<?php foreach($myForms as $form):
if($form['Form']['status']=="Completed"){ ?>
$('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).hide();
<?php }else{?>
$('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).show();
<?php } endforeach;?>
$('#sort_by').find(".selected").removeClass();
$('#Drafted').addClass("selected");
}
function submitted(){
<?php foreach($myForms as $form):
if($form['Form']['status']=="Incompleted"){?>
$('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).hide();
<?php } else{?>
$('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).show();
<?php } endforeach;?>
$('#sort_by').find(".selected").removeClass();
$('#Submitted').addClass("selected");
}
$('#All').click(all);
$('#Drafted , #formStatusDrafted').click(drafted);
$('#Submitted , #formStatusSubmitted').click(submitted);
if(document.location.hash=="#Submitted"){
submitted();
}
else if(location.hash=="#Drafted"){
drafted();
}
});
All the results are populated in the same page.I do not call any urls. I want paginations for each of these divs independent of one another. Is that possible?