'How to add Pagination to a custom made page in magento 2?
I wanted to limit the page with 10 records, i tried with this https://dolphinwebsolution.com/magento-2-add-pagination-in-custom-collection-of But it didn't worked for me, I anyone has some other suggestions please let me know. This is my code for the quote page .
Solution 1:[1]
I have solved this issue by adding a modified prepare layout in the block code. here i'm attaching the code.
enter code here protected function _prepareLayout()
{
parent::_prepareLayout();
$this->pageConfig->getTitle()->set(__('Quote'));
if ($this->getSavedQuotes()) {
$pager = $this->getLayout()->createBlock(
'Magento\Theme\Block\Html\Pager'
)->setAvailableLimit(array(10=>10,20=>20,30=>30))->setShowPerPage(false)->setCollection($this->getSavedQuotes());
$this->setChild('pager', $pager);
$this->getSavedQuotes()->load();
}
return $this;
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
public function getSavedQuotes()
{
$page = ($this->getRequest()->getParam('p')) ? $this->getRequest()->getParam('p') : 1;
$pageSize = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 10;
return $this->_quoteMainFactory->create()->getCollection()
->addFieldToFilter(
'is_deleted', 0
)->addFieldToFilter(
'status', 1
)->addFieldToFilter('customer_id', $this->customerSession->getCustomer()->getId())->setPageSize($pageSize)->setCurPage($page);;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bibin Johnson |
