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.
-
it is not as simple as that. they belong to different objects/instances, moving that button will result in fatal error. Why do you want to move that button below?– ShathishJul 18, 2013 at 7:55
-
Aesthetics. I think it would look neater inline with the other buttons. If it cannot be done, then there's no problem :)– Richard Parnaby-KingJul 18, 2013 at 9:11
1 Answer
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.