1

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!

  • ` $this->_removeButton('add');` is available in grid container class not in grid class – Minesh Patel Oct 16 '17 at 12:52
6

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

Try like this

TBF_Cupom_Block_Adminhtml_Gerados_Index extends Mage_Adminhtml_Block_Widget_Form_Container {

 public function __construct()
    {
.....
 $this->_removeButton('add');
}
}

Note: _removeButton() is not in Mage_Adminhtml_Block_Widget_Grid it is in Mage_Adminhtml_Block_Widget_Form_Container . call proper extends or proper class need to call.

  • Thank you @rama for the reply but it didn't work. Now the page shows 2 headers. The first one still contains the Add New button. And the second header displays Back, Reset and Save buttons. Further more on the content section appears this error: Fatal error: Call to a member function setData() on boolean in /var/www/html/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 147 -- here is a link to my code – Renato Aloi Aug 10 '17 at 15:34
  • I think you are something is missing in your form. please check magento.stackexchange.com/questions/138462/… – Rama Chandran M Aug 10 '17 at 19:04
  • Please provide your entire module code here i will check :) – Rama Chandran M Aug 10 '17 at 19:04
  • It is not a Form, is a list Grid. I am following to the letter this tutorial here. Thank you for the effort! – Renato Aloi Aug 10 '17 at 20:05
3

This worked for me, In your block;

protected function _construct()
    {
        parent::_construct();
        $this->buttonList->remove('add');
    }

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.