Question

I have created a custom module that shows data in a grid. How do I move the 'add new rate' button from the module header to the grid? I have not tried anything yet as I have no idea where to start.

Move button

Was it helpful?

Solution

Even if I don't see the point (but maybe I'm not that artistic) this can be done easily. First you need to remove the add button from the grid container block. This should be the block: {Namespace}/{Module}/Block/Adminhtml/{Entity}.php. At the end of the __construct method add this line:

$this->removeButton('add');

Now you need to add a button near the search button. For this you should add a method called getMainButtonsHtml in your grid block. This is {Namespace}/{Module}/Block/Adminhtml/{Entity}/Grid.php

public function getMainButtonsHtml()
{
    $html = parent::getMainButtonsHtml();//get the parent class buttons
    $addButton = $this->getLayout()->createBlock('adminhtml/widget_button') //create the add button
        ->setData(array(
            'label'     => Mage::helper('adminhtml')->__('Add'),
            'onclick'   => "setLocation('".$this->getUrl('*/*/new')."')",
            'class'   => 'task'
        ))->toHtml();
    return $addButton.$html;
}

That's it. Happy button aligning.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top