1

I don't have any idea to put pagination. I have to display all order commission details. this is the first time for me to create the front end so no idea how to create it. what are the files needed? pagination with the toolbar.

2
  • have you use any custom extension for the order commission details?
    – Abdul
    Dec 28, 2015 at 10:30
  • no i am not use any extension.
    – Monisha M
    Dec 28, 2015 at 10:42

3 Answers 3

0

I've only used this for product collections but you can give it a try. In the block behind your list PHTML file add the following method

protected function _prepareLayout()
{
    parent::_prepareLayout();

    $pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
    $pager->setAvailableLimit(array(15=>15));
    $pager->setCollection($your_collection);

    $this->setChild('pager', $pager);

    return $this;
}

and add the following in your template file

<?php echo $this->getPagerHtml(); ?>

other solution if any problem raises.

$this->getPagerHtml() in catalog\product\list\toolbar.phtml means you are trying to call getPagerHtml() method of class

Mage_Catalog_Block_Product_List_Toolbar whereas $this->getPagerHtml() in catalog/product/list.phtml means you are trying to call getPagerHtml() method of class Mage_Catalog_Block_Product_List where it is not present. If you want to call $this->getPagerHtml() in list.phtml then first you need to create object of class Mage_Catalog_Block_Product_List_Toolbar in list.phtml

Example :

$object = new Mage_Catalog_Block_Product_List_Toolbar();
$object->getPagerHtml();

I hope this will help you.

3
  • could u tell me. the file structure, which files should be edited, my requirement is when the customer is logged in to the site their commission order details should be shown. with pagination and tool bar
    – Monisha M
    Dec 28, 2015 at 11:27
  • you have to only add <?php echo $this->getPagerHtml(); ?> this will automatically add in .phtml file where you want. Dec 28, 2015 at 11:30
0

To get follow this:

echo $this->getLayout()
          ->createBlock('page/html_pager', 'order_id')
          ->setCollection($collection)
          ->toHtml();

by order_id it takes pagination

2
  • It is working. I hope it will help someone
    – Monisha M
    Dec 28, 2015 at 13:53
  • the above code should place where you need pagination
    – Monisha M
    Dec 28, 2015 at 13:54
-1

For Magento 2.3.x above

Add this into your Pager.php block file

VendoreName\ModuleName\Block\Frontend\Pager

<?php

namespace VendoreName\ModuleName\Block\Frontend\Pager;

use Magento\Framework\View\Element\Template;

class Pager extends Template
{
    protected $modalFactory;

    public function __construct(
        ..........................................
        ..........................................
        \VendoreName\ModuleName\Model\YourModalName $modalFactory,
        ..........................................
        ..........................................
    ) {
        ..........................................
        ..........................................
        $this->modalFactory = $modalFactory;
        ..........................................
        ..........................................
    }
    protected function _prepareLayout()
    {
        $this->pageConfig->getTitle()->set(__('Pager Show'));
        parent::_prepareLayout();
        $page_size = [];
        $page_size[5] = 5;
        $page_size[10] = 10;
        $page_size[15] = 15;
        $pager_collection = $this->getPager();
        if ($this->getPager()) {
            $pager = $this->getLayout()->createBlock(
                \Magento\Theme\Block\Html\Pager::class,
                'my.custom.pager'
            )
                ->setAvailableLimit($page_size)
                ->setShowPerPage(true)
                ->setCollection($pager_collection);
            $this->setChild('pager', $pager);
            $this->getPager()->load();
        }
        return $this;
    }
    public function getPagerHtml()
    {
        return $this->getChildHtml('pager');
    }
    public function getPager()
    {
        $page = ($this->getRequest()->getParam('p')) ? $this->getRequest()->getParam('p') : 1;
        
        $pageSize = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 5;

        $collection = $this->modalFactory->getCollection();
        $collection->setPageSize($pageSize);
        $collection->setCurPage($page);
        return $collection;
    }
}

Add this into your pager.phtml file

VendoreName\ModuleName\view\frontend\templates

.................................................................
.................................................................
.................................................................
    <?php if ($block->getPagerHtml()): ?>
            <div class="order-products-toolbar toolbar bottom">
                <?= $block->getPagerHtml() ?>
            </div>
    <?php endif ?>

And finally add into your layout file

<block class="VendoreName\ModuleName\Block\Frontend\Pager\Pager" name="pager_demo" template="VendoreName_ModuleName::pager.phtml" cacheable="false">

Run magento command

php bin/magento s:up

php bin/magento s:s:d -f 

php bin/magento c:c

I Hope This Helps You.

2
  • Question was about M1.
    – sv3n
    Feb 11 at 0:16
  • @sv3n in my opinion though it's m1 question but M2 answer add value to it, I am not sure, let's ask question in meta and let's check community opinion Feb 11 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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