Magento 1.7 – Using Pagination with Custom Collections

magento-1.7

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>

Best Answer

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(); ?>
Related Topic