Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

remove add button from grid
 
Matthieu MARY
Member
 
Total Posts:  33
Joined:  2008-08-28
France
 

hello everybody,

I’m looking to remove the add button from my override grid in my new module.
My new module display grid fine, but I want to remove the add button.
I have found that this button is build from Mage_Adminhtml_Block_Widget_Grid_Container block.
but I do not wants to override this block for all magento modules, just for mine.
I’m not sure how to do this only for my module.
Do you have an idea?
Best regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
youngilaboungi
Jr. Member
 
Avatar
Total Posts:  28
Joined:  2008-11-27
Alexandria, Egypt
 

you are building your module under the MAGE module, any edit will be overridden on upgrades as well as ur file will affect the rest of modules under MAGE.
build ur module in your “local” folder not in “core” with all needed folders and structure, that’s the beauty of magento smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael Wai
Member
 
Total Posts:  34
Joined:  2010-04-15
 
Matthieu MARY - 21 September 2008 09:02 AM

hello everybody,

I’m looking to remove the add button from my override grid in my new module.
My new module display grid fine, but I want to remove the add button.
I have found that this button is build from Mage_Adminhtml_Block_Widget_Grid_Container block.
but I do not wants to override this block for all magento modules, just for mine.
I’m not sure how to do this only for my module.
Do you have an idea?
Best regards,

Although it’s almost two years passed, but still value to answer ...

Recently I also want to remove the add button in admin page, after checking the codes, it’s really easy to do so:

parent::__construct();
$this->removeButton(’add’);

Just put the codes in blue color after the “parent::__construct();” in your object which extends Mage_Adminhtml_Block_Widget_Grid_Container.

Hope this help.

Michael Wai

 
Magento Community Magento Community
Magento Community
Magento Community
 
ayasoftware
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2009-06-02
 

Hello,
I tried to remove “add new” button from Grid, but I’m receiving this error:

Fatal error: Call to a member function setSaveParametersInSession() on a non-object in /chroot/home/yyyyy/xxxxxx.com/html/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php on line 59

Here is the code I have changed :

public function __construct()
{
parent::__construct();
$this->removeButton(’add’);
}

any idea, how to get rid of this error.

Regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magazento
Sr. Member
 
Avatar
Total Posts:  155
Joined:  2010-01-08
Russia,Volgograd
 

just remove parent::__construct(); from class
exemple:

<?php
/*
* Created on Mar 16, 2011
* Author Ivan Proskuryakov - - Magazento.com
* Copyright Proskuryakov Ivan. Magazento.com © 2011. All Rights Reserved.
* Single Use, Limited Licence and Single Use No Resale Licence ["Single Use"]
*/
?>
<?php

class Magazento_Voucher_Block_Admin_Item extends Mage_Adminhtml_Block_Widget_Grid_Container
{
// public function __construct()
// {
// parent::__construct();
//
// $this->setTemplate(’widget/grid/container.phtml’);
//
// $this->_addButton(’add’, array(
// ‘label’ => $this->getAddButtonLabel(),
// ‘onclick’ => ‘setLocation(\’’ . $this->getCreateUrl() .’\’)’,
// ‘class’ => ‘add’,
// ));
// }

public function __construct()
{
$this->_controller = ‘admin_item’;
$this->_blockGroup = ‘voucher’;
$this->_headerText = Mage::helper(’voucher’)->__(’Voucher Items grid’);
$this->setTemplate(’widget/grid/container.phtml’);
// $this->_addButtonLabel = Mage::helper(’voucher’)->__(’Add New Item’);
// parent::__construct();
}

}

 
Magento Community Magento Community
Magento Community
Magento Community
 
rdejesica
Jr. Member
 
Total Posts:  1
Joined:  2011-07-05
 
Matthieu MARY - 21 September 2008 09:02 AM

hello everybody,

I’m looking to remove the add button from my override grid in my new module.
My new module display grid fine, but I want to remove the add button.
I have found that this button is build from Mage_Adminhtml_Block_Widget_Grid_Container block.
but I do not wants to override this block for all magento modules, just for mine.
I’m not sure how to do this only for my module.
Do you have an idea?
Best regards,

<?php
class <Namespace>_<Module>_Block_Adminhtml_<Module> extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = ‘adminhtml_<module>’;
$this->_blockGroup = ‘<module>’;
$this->_headerText = Mage::helper(’<module>’)->__(’My Custom Module’);
// $this->_addButtonLabel = Mage::helper(’<module>’)->__(’Add Item’); /*Comment out this line*/
parent::__construct();
$this->_removeButton(’add’); /*Add this line after calling parent constructor*/
}
}/code]

 
Magento Community Magento Community
Magento Community
Magento Community
 
cyberluna
Jr. Member
 
Total Posts:  15
Joined:  2011-06-23
 

http://cyberluna.wordpress.com/2011/08/11/remove-add-button-magento/

 
Magento Community Magento Community
Magento Community
Magento Community
 
spider2012
Jr. Member
 
Total Posts:  7
Joined:  2012-03-06
 

Thanks Michael Wai…

parent::__construct();
$this->removeButton('add');

The above code solves my problem. It removes add button above the grid.  smirk

 
Magento Community Magento Community
Magento Community
Magento Community
 
kunjesh
Jr. Member
 
Total Posts:  17
Joined:  2010-03-08
 

Thank You Michael Wai

$this->removeButton('add');
This code solve my problem. Thanks a lot.
 
Magento Community Magento Community
Magento Community
Magento Community
 
kielsoft
Jr. Member
 
Total Posts:  1
Joined:  2013-04-24
 

Thanks, this is helpful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kaushikam
Jr. Member
 
Total Posts:  2
Joined:  2012-08-17
 

I think it will be wise to use the following format.

As all of you know that there is a method

_beforeToHtml()

, use that function in the grid container block class

public function _beforeToHtml() {
        $this
->removeButton('add');
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top