1

I've build a custom extension but now I would like to add some data from this extension to the dashboard page. To be precise I would like to add it to the tabs you see in the image attached.

Can someone point me in the right direction on how to go about doing something like that? Thanks in advance.

enter image description here

4

The tabs are added in Mage_Adminhtml_Block_Dashboard_Grids::_prepareLayout.
Here is how a tab structure looks like:

$this->addTab('reviewed_products', array(
        'label'     => $this->__('Most Viewed Products'), //label
        'url'       => $this->getUrl('*/*/productsViewed', array('_current'=>true)), //url that returns the content
        'class'     => 'ajax' //marker that the content is requested through ajax.
    ));

You can add tab that does not retrieve data through ajax.

$this->addTab('ordered_products', array(
        'label'     => $this->__('Bestsellers'), //label
        'content'   => $this->getLayout()->createBlock('adminhtml/dashboard_tab_products_ordered')->toHtml(), //tab content
        'active'    => true //mark this as the active tab
    ));

What you can do is to override the method above and add your own tabs (content or ajax).
[EDIT]
Here is how you can override a block And in your new block do this:

protected function _prepareLayout(){
    parent::_prepareLayout();//add original tabs
    $this->addTab('custom', array(
        'label'     => $this->__('Custom'), //label
        'url'       => $this->getUrl('*/controller/action', array('_current'=>true)), //url that returns the content
        'class'     => 'ajax' //marker that the content is requested through ajax.
    ));
    //or 
    $this->addTab('other_tab', array(
        'label'     => $this->__('Some label'), //label
        'content'   => $this->getLayout()->createBlock('custom/block_name')->toHtml(), //tab content
    ));
    return $this;
}

[Second degree edit]
Here is a small sample module that does this. Let's call it Easylife_Test.
app/etc/modules/Easylife_Test.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Test>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Adminhtml />
            </depends>
        </Easylife_Test>
    </modules>
</config>

app/code/local/Easylife/Test/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylive_Test>
            <version>0.0.1</version>
        </Easylive_Test>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <dashboard_grids>Easylife_Test_Block_Adminhtml_Dashboard_Grids</dashboard_grids>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

app/code/local/Easylife/Test/Block/Adminhtml/Dashboard/Grids.php - the new block

<?php
class Easylife_Test_Block_Adminhtml_Dashboard_Grids extends Mage_Adminhtml_Block_Dashboard_Grids{
    protected function _prepareLayout(){
        parent::_prepareLayout();
        $this->addTab('custom', array(
            'label'     => $this->__('Custom tab'),
            'content'   => 'content here',
        ));
    }
}
  • how to done this with block rewire? i need to retrieve data through ajax. – MeenakshiSundaram R Sep 30 '13 at 18:02
  • <adminhmtl> <rewrite> <dashboard_grids>My_Module_Block_Dashboard_Grids</dashboard_grids> </rewrite> </adminhmtl> is this correc?t – MeenakshiSundaram R Sep 30 '13 at 18:11
  • 1
    @MeenakshiSundaramR. It seams correct. The best way to find out is to try it. – Marius Sep 30 '13 at 18:16
  • thanks marius,class My_Module_Block_Dashboard_Grids extends Mage_Adminhtml_Block_Dashboard_Grids { protected function _prepareLayout() { parent::_prepareLayout(); $this->addTab('mytab', array( 'label' => $this->__('Mytab'), 'url' => $this->getUrl('*/*/productsViewed', array('_current'=>true)), 'class' => 'ajax' )); return $this; } }this is rewrite class code but i didnt output. – MeenakshiSundaram R Sep 30 '13 at 18:19
  • i need to get my custom module grid here.Could you explain it more detail – MeenakshiSundaram R Sep 30 '13 at 18:21

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.