Magento – How to remove ‘Add New’ button from Admin Grid in Magento 1.9

adminhtmlgridmagento-1.9widget

I am trying to remove the Add New button from an Adminhtml grid in Magento 1.9.

I have found this post and [this other one]
(Magento 2 – How to remove "Add new MODEL" button on \Magento\Backend\Block\Widget\Grid\Container) about doing that in Magento 2.0, but the same technique does not apply to Magento 1.9.

The error reported in Magento 1.9 is this:

exception 'Varien_Exception' with message 'Invalid method TBF_Cupom_Block_Adminhtml_Gerados_Index_Grid::_removeButton(Array
(
    [0] => add
)
)' in /var/www/html/lib/Varien/Object.php:653

In fact it makes sense because Grid's parent class is Mage_Adminhtml_Block_Widget_Grid and it does not have a _removeButton() method.

So, the question remains… How can I remove the Add New button from an Admin Grid Widget in Magento 1.9?

Thanks in advance!

Best Answer

Renate, if you are following the tutorial, then you'll need to add the code suggested by Rama to this section

<?php
class Foo_Bar_Block_Adminhtml_Baz extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
    // The blockGroup must match the first half of how we call the block, and controller matches the second half
    // ie. foo_bar/adminhtml_baz
        $this->_blockGroup = 'foo_bar';
        $this->_controller = 'adminhtml_baz';
        $this->_headerText = $this->__('Baz');

        parent::__construct();

        // must be placed after the parent::__construct();
        $this->_removeButton('add');
    }
}