1

I have filtered customer collection and showing in account navigation with one new custom link. upon clicking custom link on left nav i need to show collection on right side with pagination.

How this can be done? So far i am able to bring custom link on left nav and after clicking on it getting customer collection. How to add pagination to it with limit ? Is that can be done. please advice anyone.

  • please review this blog.qaisarsatti.com/magento_2/… – Shorabh Aug 3 '18 at 8:56
  • can you explain in detail , i want to add pagination for my custom collection on customer account navigation. Already i bought the link on left nav with collection. how to show that in pagination? – jafar pinjar Aug 3 '18 at 9:07
  • Can you update your code to the question? – Sukumar Gorai Aug 3 '18 at 10:46
0

Use the below method

$collection->setPageSize()
| improve this answer | |
  • So it will show pagination this line? Please explain elaborately – jafar pinjar Aug 3 '18 at 9:22
  • just check vendor/magento/module-backend/view/adminhtml/templates/widget/grid/extended.phtml You will now what to do. – Avesh Naik Aug 3 '18 at 9:25
  • @AveshNaik what you mean You will now what to do??? – jibin george Jul 5 '19 at 13:51
0

Add code in your block file.


protected $_productFactory;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Catalog\Model\ProductFactory $productFactory,
    array $data = []
) {
    $this->_productFactory = $productFactory;
    parent::__construct($context, $data);
}

public function displayCollection()
{
    //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;

    // get your collection here for ex:- $this->_productFactory->create()->getCollection() 
    $productCollection =  $this->_productFactory->create()->getCollection();
    $productCollection->setPageSize($pageSize);
    $productCollection->setCurPage($page);
    return $productCollection;
}
protected function _prepareLayout()
{
    parent::_prepareLayout();

    if ($this->displayCollection()) {
        $pager = $this->getLayout()->createBlock(
            'Magento\Theme\Block\Html\Pager',
            'Your_module_namespace.Your_module_name.record.pager'
        )->setAvailableLimit(array(10 => 10, 15 => 15, 20 => 20, 25 => 25))->setShowPerPage(true)->setCollection(
            $this->displayCollection()
        );
        $this->setChild('pager', $pager);
        $this->displayCollection()->load();
    }
    return $this;
}

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

Add code in your phtml file.

<?php
if ($block->displayCollection()) {
    $custommodel = $block->displayCollection();
}
?>
<?php if($custommodel && count($custommodel)): ?>
    <?php foreach ($custommodel as $value):?>
       //get your content here
    <?php endforeach; ?>
<?php if ($block->getPagerHtml()): ?>
    <div class="order-products-toolbar toolbar bottom custom-pager"><?php echo $block->getPagerHtml(); ?></div>
    <?php endif ?>
<?php else: ?>
    <div class="message info empty" ><span><?php echo __('You have no any data.....'); ?></span></div>
<?php endif; ?>
| improve this answer | |
  • 1
    What is Your_module_namespace.Your_module_name.record.pager? namespace and module_name i will replace with mine, what is record and pager? – jafar pinjar Aug 3 '18 at 10:50
  • any update about this? – jibin george Aug 5 '19 at 15:21

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.