Magento – Add custom module Tab(gird) in admin Dashboard

adminadminhtmlmagento-1.7

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

Best Answer

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',
        ));
    }
}