4

It is posible to use magento standard pagination with custom colections ( not product ) ?

I am using a module , it display list of manufacturers and i need to add there pagination.

I used this code to display toolbar:

$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();

$toolbar->setCollection($_manufacturersCollection);

$toolbarHtml =  $toolbar->toHtml();

Toolbar apeared and total number is corect but pagination is not displayed

in XML added this

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                <block type="page/html_pager" name="product_list_toolbar_pager"/>
                <!-- The following code shows how to set your own pager increments -->
                <!--
                    <action method="setDefaultListPerPage"><limit>4</limit></action>
                    <action method="setDefaultGridPerPage"><limit>9</limit></action>
                    <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
                    <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
                    <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
                    <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
                    <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                -->
            </block>

            <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>

1 Answer 1

11

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(); ?>
2
  • Thanks for answer , calling pager directly without toolbar using "$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');" is working. I used this in .phtml and just added limits to collection.
    – user4157
    Dec 13, 2013 at 13:10
  • @SanderMangel I have followed the same thing, but all my collection not loading in all pagination's pages: magento.stackexchange.com/questions/229743/…
    – Sushivam
    Jun 14, 2018 at 11:46

Your Answer

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

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