2

I am trying to get pagination on my collection in block when i call from PHTML file it returns nothing, not showing pagination but $pageSize is working fine. This function getPagerHtml() in phtml is not working

here is my function

  public function getTransactionsArchive(){
        //get values of current page
        $page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
    //get values of current limit
        $pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest()->getParam('limit') : 10;


        $customer_id = $this->request->getParam('id');
        $filters = array("customer_id" => $customer_id,"status" => 2,"cm_transaction_date" => array('to' => date("Y-m-01 00:00:00")));


        $transactionFactory = $this->_transactionFactory->create();
        $Collection = $transactionFactory->getCollection();
        foreach($filters as $filter => $value){
            $Collection->addFieldToFilter($filter, $value);
        }
        $Collection->setPageSize($pageSize);
        $Collection->setCurPage($page);

        return $Collection;
    }

and here is my layout function

  protected function _prepareLayout()
    {
        parent::_prepareLayout();
        if ($this->getTransactionsArchive()) {
            // create pager block for collection
            $pager = $this->getLayout()->createBlock('Magento\Theme\Block\Html\Pager','my.custom.pager');
             // assign collection to pager
            $pager->setLimit(10)->setCollection($this->getTransactionsArchive());
            $pager->setAvailableLimit([10=>10,20=>20,50=>50,100=>100]);
            $this->setChild('pager', $pager);// set pager block in layout
        }
        return $this;
}

and this is my pagerhtml

public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}

and in my phtml calling this as

<?php if ($this->getPagerHtml()):
<div class="toolbar bottom"><?php echo $this->getPagerHtml(); ?></div>
<?php endif ?>
  • Did you get any solution? I m also facing that issue @Asad Ullah – divya sekar Sep 21 at 11:21
  • To be honest its a long time back i forgot how i resolved it sorry man @divyasekar – Asad Ullah Sep 21 at 14:07
0

Add $this->getTransactionsArchive() in _prepareLayout()

  protected function _prepareLayout()
    {
        parent::_prepareLayout();
        if ($this->getTransactionsArchive()) {
            // create pager block for collection
            $pager = $this->getLayout()->createBlock('Magento\Theme\Block\Html\Pager','my.custom.pager');
             // assign collection to pager
            $pager->setLimit(10)->setCollection($this->getTransactionsArchive());
            $pager->setAvailableLimit([10=>10,20=>20,50=>50,100=>100]);
            $this->setChild('pager', $pager);// set pager block in layout
            $this->getTransactionsArchive()->load(); //Add This
        }
        return $this;
}
| improve this answer | |
  • tried this nothing.....still the same – Asad Ullah Jul 23 '19 at 13:49
  • do you any other solution? – Asad Ullah Jul 24 '19 at 5:31

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.