1

This question already has an answer here:

I want custom grid in tab

I have created a custom module in the admin panel and now want to create a grid to show, filter, etc the data under a tab from a custom table. As like below screen

enter image description here

Right Now My tab comes like as bellow screen

enter image description here

I have added a Tab in Tab.php file

class Bluehorse_Warehouse_Block_Adminhtml_Warehouse_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
        public function __construct()
        {
                parent::__construct();
                $this->setId('warehouse_tabs');
                $this->setDestElementId('edit_form');
                $this->setTitle(Mage::helper('warehouse')->__('Warehouse '));
        }
        protected function _beforeToHtml()
        {
                $this->addTab('warehouse', array(
                    'label' => Mage::helper('warehouse')->__('Warehouse Information'),
                    'title' => Mage::helper('warehouse')->__('Warehouse Information'),
                    'content' => $this->getLayout()->createBlock('warehouse/adminhtml_warehouse_edit_tab_form')->toHtml(),
                ));
                $this->addTab('zipcoe', array(
                    'label'     => Mage::helper('warehouse')->__('Associated Zip Code'),
                    'title'     => Mage::helper('warehouse')->__('Associated Zip Code'),
                    'url'       => $this->getUrl('*/*/pincodes', array('_current' => true)),
                    'class'     => 'ajax',
                ));


                return parent::_beforeToHtml();
        }

}

Added a function

class Bluehorse_Warehouse_Adminhtml_WarehouseController extends Mage_Adminhtml_Controller_Action
{
    public function pincodesAction () {
    //      

    }

  ................

There are my two tables one is

    +--------------+------------------+------+-----+---------+----------------+
    | Field        | Type             | Null | Key | Default | Extra          |
    +--------------+------------------+------+-----+---------+----------------+
    | id           | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | firstname    | varchar(255)     | NO   |     |         |                |
    | lastname     | varchar(255)     | NO   |     |         |                |
    | phone        | varchar(255)     | NO   |     |         |                |
    | email        | varchar(255)     | NO   |     |         |                |
    | username     | varchar(255)     | NO   |     |         |                |
    | password     | varchar(255)     | NO   |     |         |                |
    | name         | varchar(255)     | NO   |     |         |                |
    | zone         | varchar(255)     | NO   |     |         |                |
    | zipcode      | varchar(255)     | NO   |     |         |                |
    | address      | text             | NO   |     | NULL    |                |
    | status       | smallint(6)      | NO   |     | 0       |                |
    | created_time | date             | YES  |     | NULL    |                |
    | update_time  | date             | YES  |     | NULL    |                |
    +--------------+------------------+------+-----+---------+----------------+

Second is

    +---------------+------------------+------+-----+---------+----------------+
    | Field         | Type             | Null | Key | Default | Extra          |
    +---------------+------------------+------+-----+---------+----------------+
    | id            | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | wid           | varchar(255)     | NO   |     | NULL    |                |
    | zipcode       | varchar(255)     | NO   |     | NULL    |                |
    | is_primary    | varchar(255)     | NO   |     | 0       |                |
    | delivery_time | varchar(255)     | NO   |     | NULL    |                |
    | status        | smallint(6)      | NO   |     | 0       |                |
    | position      | smallint(6)      | NO   |     | 0       |                |
    | created_at    | timestamp        | YES  |     | NULL    |                |
    | updated_at    | timestamp        | YES  |     | NULL    |                |
    +---------------+------------------+------+-----+---------+----------------+

I want to showing a grid under my blank tab. How can do it? Can you help me.

I also take help from

How to create the Product Grid Serializer Block In Custom module

marked as duplicate by Siarhey Uchukhlebau, Qaisar Satti, Raphael at Digital Pianism, Rakesh Jesadiya, 7ochem Jan 5 '17 at 16:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You need to add below code in action

class Bluehorse_Warehouse_Adminhtml_WarehouseController extends Mage_Adminhtml_Controller_Action
{
    public function pincodesAction () {
        $this->loadLayout();
        $this->getLayout()->getBlock('edit.tab.pincodes');        
        $this->renderLayout();   

    }
}

Crete a grid file as below

class Bluehorse_Warehouse_Block_Adminhtml_Edit_Tab_Pincodes extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('pincodeGrid');
        $this->setUseAjax(true); // Using ajax grid is important
        $this->setDefaultSort('entity_id');             
    }

    protected function _getStore()
    {
        $storeId = (int) $this->getRequest()->getParam('store', 0);
        return Mage::app()->getStore($storeId);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('Your-Model-Name')->getCollection();

        $this->setCollection($collection);

         parent::_prepareCollection();
        return $this;
    }

    protected function _prepareColumns()
    {

        //add column here

        return parent::_prepareColumns();
    }

}

Add below code to admin layout update file of your module

<adminhtml_warehouse_pincodes>
        <block type="core/text_list" name="root" output="toHtml">
            <block type="warehouse/adminhtml_edit_tab_pincodes" name="edit.tab.pincodes"/>
        </block>
    </adminhtml_warehouse_pincodes>
  • Nothing is coming in grid tab. Can you check it?? – Supravat M Mar 23 '16 at 10:33
  • You need to do some modification as per your model name, layout block name. – Prashant Valanda Mar 23 '16 at 10:52

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