I want to add pagination in custom data collection Magento 1.x. I found it and tried but it not working.

My table

enter image description here

My collection

public function getProductReturn(){
         $collection = Mage::getModel('catalog/product')->getCollection()
                $collection->setPage(2, 6);
          return $collection;

2 Answers 2


->setPageSize(10) ->setCurPage(1);

Try above. You will get first 10 products. If you set CurPage to 2, you will get next 10 products. To understand simply, setting 2 returns 11 to 20 result.


You can use this code for pagination

In your Block file

    public function __construct()
        $collection = Mage::getModel('custom/collection')->getCollection();

    protected function _prepareLayout()

        $pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
        $this->setChild('pager', $pager);
        return $this;

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

In your phtml file add this line at last <?php echo $this->getPagerHtml(); ?>

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $collection = $this->getCollection(); ?>
    <h1><?php echo $this->__('My Custom Collection') ?></h1>
<?php echo $this->getPagerHtml(); ?>
<?php if($collection->getSize()): ?>
<table id="my-custom-table">
    <col width="1" />
    <col width="1" />
    <col />
    <col width="1" />
    <col width="1" />
    <col width="1" />
            <th><?php echo $this->__('ID #') ?></th>
            <th><?php echo $this->__('Title') ?></th>
            <th><span><?php echo $this->__('Created') ?></span></th>
        <?php $_odd = ''; ?>
        <?php foreach ($collection as $_obj): ?>
                <td><?php echo $_obj->getCollectionId() ?></td>
                <td><span><?php echo $_obj->getTitle(); ?></span></td>
                <td><?php echo $this->formatDate($_obj->getCreatedTime()) ?></td>
        <?php endforeach; ?>
<script type="text/javascript">decorateTable('my-custom-table');</script>
<?php echo $this->getPagerHtml(); ?>
<?php else: ?>
    <p><?php echo $this->__('The collection is empty.'); ?></p>
<?php endif ?>


Hope it Helps.

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.