1

I have added a custom tab in customer admin view.

My tab class content is :

class Namespace_Modulename_Block_Adminhtml_Customer_Edit_Tab
extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface 
{
    public function __construct()
    {
        $this->setTemplate('tab/tab.phtml');
    }
}

And in tab.phtml I have custom collection and want to add pagination.

How to add pagination for custom collection here?

0

I got a solution :

I created a grid.php in my custom module for custom collection and add grid in tab.phtml as below :

echo $this->getLayout()->createBlock('custom/adminhtml_path_grid')->toHtml();
|improve this answer|||||
0

Step1: Controller, First in our IndexController we will simply load the layout and render it.

<?php
class Excellence_Collection_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {

        $this->loadLayout();    
        $this->renderLayout();
    }
}

Step2: Layout, In our module layout file, i.e collection.xml this is the code to put

<?xml version="1.0"?>
<layout version="0.1.0">
    <collection_index_index>
        <reference name="content">
            <block type="collection/collection" name="collection" template="collection/collection.phtml" />
        </reference>
    </collection_index_index>
</layout>

Step3: Block, Next we will create our block collection/collection where the main code for paging goes.

<?php
class Excellence_Collection_Block_Collection extends Mage_Core_Block_Template
{

    public function __construct()
    {
        parent::__construct();
        $collection = Mage::getModel('collection/collection')->getCollection();
        $this->setCollection($collection);
    }

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

        $pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
        $pager->setAvailableLimit(array(5=>5,10=>10,20=>20,'all'=>'all'));
        $pager->setCollection($this->getCollection());
        $this->setChild('pager', $pager);
        $this->getCollection()->load();
        return $this;
    }

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

As you can see in the above code we have created a block for the pager and set our collection in it. Step4: phtml file, Next in our collection.phtml file we need to put in this code

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $collection = $this->getCollection(); ?>
<div class="page-title">
    <h1><?php echo $this->__('My Collection') ?></h1>
</div>
<?php echo $this->getPagerHtml(); ?>
<?php if($collection->getSize()): ?>
<table class="data-table" id="my-custom-table">
    <col width="1" />
    <col width="1" />
    <col />
    <col width="1" />
    <col width="1" />
    <col width="1" />
    <thead>
        <tr>
            <th><?php echo $this->__('ID #') ?></th>
            <th><?php echo $this->__('Title') ?></th>
            <th><span class="nobr"><?php echo $this->__('Created') ?></span></th>
        </tr>
    </thead>
    <tbody>
        <?php $_odd = ''; ?>
        <?php foreach ($collection as $_obj): ?>
        <tr>
            <td><?php echo $_obj->getCollectionId() ?></td>
            <td><span class="nobr"><?php echo $_obj->getTitle(); ?></span></td>
            <td><?php echo $this->formatDate($_obj->getCreatedTime()) ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<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 ?>

This is all that is required, now the paging should show up on your collection.

Showing Toolbar on Custom Collection Now we will add a toolbar to our custom collection, i.e will add sorting and view modes. Here is the end result of the code

enter image description here

|improve this answer|||||
  • I will try it and will let you know. – Vinaya Maheshwari Jan 7 '17 at 13:51
  • ok sure.........let me know if you have any issue with that. – Vishal Thakur Jan 7 '17 at 20:44
  • Hello, I tried but it is not working, this is working in frontend template but as I said I have to implement it is in admin panel in customer section where I added a custom tab. – Vinaya Maheshwari Jan 9 '17 at 4:19

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.