3

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

  • 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? – Shathish Jul 18 '13 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-King Jul 18 '13 at 9:11
11

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.

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.