3

I have made a custom module in magento admin. In which I am showing a custom tab on CMS page area as shown in below image.

enter image description here

I have a custom form on click on "My Button". I fill that form and value is properly inserted in DB.

Now I want to show Grid for saved data under my custom tab for that form.

How can I do this on CMS Page area in Magento admin..?

Please help me to get rid of this problem.

Thanks

1

Not sure what part of the code you already have, here a complete walk-thru on how to add a grid to the CMS Page edit:

I named my example Example_CmsTabGrid:

Module init file: /app/etc/modules/Example_CmsTabGrid.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Example_CmsTabGrid>
            <active>true</active>
            <codePool>community</codePool>
        </Example_CmsTabGrid>
    </modules>
</config>

Module config file: /app/code/community/Example/CmsTabGrid/etc/config.xml:

<config>
    <modules>
        <Example_CmsTabGrid>
            <version>1.0.0</version>
        </Example_CmsTabGrid>
    </modules>

    <global>
        <blocks>
            <example_cmstabgrid>
                <class>Example_CmsTabGrid_Block</class>
            </example_cmstabgrid>
        </blocks>

        <helpers>
            <example_cmstabgrid>
                <class>Example_CmsTabGrid_Helper</class>
            </example_cmstabgrid>
        </helpers>
    </global>

    <adminhtml>
        <layout>
            <updates>
                <example_cmstabgrid>
                    <file>example_cmstabgrid.xml</file>
                </example_cmstabgrid>
            </updates>
        </layout>
    </adminhtml>
</config>

Helper: /app/code/community/Example/CmsTabGrid/Helper/Data.php:

<?php

class Example_CmsTabGrid_Helper_Data extends Mage_Core_Helper_Abstract
{

}

Layout file to add tab to cms_page_edit: /app/design/adminhtml/default/default/layout/example_cmstabgrid.xml:

<?xml version="1.0"?>
<layout>
    <adminhtml_cms_page_edit>
        <reference name="cms_page_edit_tabs">
            <action method="addTab">
                <name>example_cmstabgrid</name>
                <block>example_cmstabgrid/cms_page_edit_tab_grid</block>
            </action>
        </reference>
    </adminhtml_cms_page_edit>
</layout>

And the last file that combines the Tab interface with the Grid combined: /app/code/community/Example/CmsTabGrid/Block/Cms/Page/Edit/Tab/Grid.php:

<?php

class Example_CmsTabGrid_Block_Cms_Page_Edit_Tab_Grid
    extends Mage_Adminhtml_Block_Widget_Grid implements Mage_Adminhtml_Block_Widget_Tab_Interface
{

    /**
     * Get tab label
     *
     * @return string
     */
    public function getTabLabel()
    {
        return Mage::helper('example_cmstabgrid')->__('Blocks');
    }

    /**
     * Get tab title
     *
     * @return string
     */
    public function getTabTitle()
    {
        return Mage::helper('example_cmstabgrid')->__('Blocks');
    }

    /**
     * Check if tab can be displayed
     *
     * @return boolean
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * Check if tab is hidden
     *
     * @return boolean
     */
    public function isHidden()
    {
        return false;
    }

    public function __construct()
    {
        parent::__construct();
        $this->setId('myTabGrid');
        $this->setUseAjax(false);
        $this->setDefaultSort('entity_id');
        $this->setDefaultDir('DESC');
        $this->setEmptyText(Mage::helper('example_cmstabgrid')->__('No records found!'));
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('cms/block')
            ->getCollection();

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {

        $this->addColumn(
            'identifier',
            array(
                'header' => Mage::helper('example_cmstabgrid')->__('Identifier'),
                'width' => '200px',
                'index' => 'identifier',
            )
        );

        $this->addColumn(
            'is_active',
            array(
                'header' => Mage::helper('example_cmstabgrid')->__('Active'),
                'index' => 'is_active',
                'type' => 'options',
                'options' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray(),
            )
        );

        $this->addColumn(
            'title',
            array(
                'header' => Mage::helper('example_cmstabgrid')->__('Title'),
                'index' => 'title',
            )
        );


    }

    public function getRowUrl($row)
    {
        return false;
    }

}

Hope this helps you with what you are looking for.

  • very detailed answer (y) – Hashid Dec 4 '14 at 11:20
1

You can Call another Grid Via 2 Ways. Hope You know the whole structure of Magento Grid Management.

Step 1: Open your Module Folder like [NameSpace]\[Module Name]\Block\Adminhtml\[modulename]\Edit\Tabs.php.

Step 2: In _beforeToHtml() Method add last Below Code.

  $this->addTab("Custom Block", array(
        "label" => Mage::helper("custom")->__("Custom Block"),
        "title" => Mage::helper("reordermanagement")->__("Custom Block"),
        'content' => $this->getLayout()->createBlock('[modulename]/adminhtml_[anothermoduleanme]_grid', 'custom-tab-content')->toHtml(),            
        'class' => 'ajax'
    ));

Step 3: This is one Way to add the Custom grid to another tab grid.

Or

Step2: Another Way is to create a action in controller.

Step 3: Add Below Code.

$this->addTab("reorder History", array(
        "label" => Mage::helper("reordermanagement")->__("Reorder History"),
        "title" => Mage::helper("reordermanagement")->__("Reorder History"),            
        'url'=>$this->getUrl('*/*/grid', array('_current'=>true)),
        'class' => 'ajax'
    ));

Step 4: Create gridAction() Method in [Namespace]\[Module Name]\controllers\Adminhtml\yourController.php and create Below Method.

 public function gridAction()
 {
    $this->getResponse()->setBody(
        Mage::app()->getLayout()->createBlock('[modulename]/adminhtml_[anothermoduleanme]_grid')->toHtml()
    );
}

These are the simple steps to add Grid into Custom tab.

  • Hello @keyul, I have no file named "Tabs.php" at location specified by you. I want to tell you that I have created custom tab with xml file in layout in adminhtml folder. – Shashank Kumrawat Dec 3 '14 at 14:32
  • Then you have to change the logic to add the tab and you have to over ride the core class and added your code – Keyul Shah Dec 3 '14 at 16:31

protected by Keyul Shah Dec 3 '14 at 7:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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