0

am working on custom module. How can i use default magento pagination use ajax with my custom collection and also set custom limits on that?

0

You can try to pass the page number in your Ajax request like below :

function uploaddata() {
new Ajax.Request("<?php echo $this->getUrl('*/*/ajaxtry'); ?>"+'page/'+page_number, {
    method: "post",
    onSuccess: function(transport) {
    var json = transport.responseText.evalJSON();
    if(json.NextPageToFetch !== 'undefined' && (page_number == json.NextPageToFetch)) {
       id++;
       page_number = 1;
    } else if (json.NextPageToFetch !== 'undefined' && (page_number != json.NextPageToFetch)) {
       page_number = json.NextPageToFetch;
       } else {
       page_number = 1;
    }

    if (id < totalPages) {
        uploaddata();
    } 
  }
}

Then in ajax controller you can retrieve data from collection by using pagination like this :

$page = $this->getRequest()->getParam('page', 1);
$collection->setPageSize(50)
                    ->setCurPage($page)
                    ->setOrder('id','DESC');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.