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 ?>