Page 1 of 1

Adding button to grid container block via controller

PostPosted: Wed Oct 04, 2017 11:50 am
by theSeeker
Is it possible to add a button to my 'grid container button' via the controller.

The reason for this is that i want to place params within the button based upon the originating URL.

I am aware that i can use an observer to add a button i.e

Code: Select all
publicfunction beforeContainerHtml($observer)
      $block = $observer->getBlock();

     if($block instanceofMage_Adminhtml_Block_Cms_Block_Edit){
          $product =Mage::registry('current_product');

          $block->addButton('magently_notify_duplicate', array(
              'label'     =>Mage::helper('adminhtml')->__('Duplicate'),
              'onclick'   =>'setLocation(\''. $block->getUrl('*/magently_notify/duplicate/block_id/'. $block_id).'\')',
              'class'     =>'duplicate',

However, this is not suitable because i need to change the params based on the originating URL.

I tried this but it did not work:

Code: Select all
$block = $this->getLayout()
        ->addButton('magently_notify_duplicate', array(
      'label'     => Mage::helper('adminhtml')->__('Duplicate'),
      'onclick'   => 'setLocation(\'' . $block->getUrl('*/magently_notify/duplicate/block_id/' . $block_id) . '\')',
      'class'     => 'duplicate',
   ), -1, 0);

The error message was that the add button not a defined method.

If its not possible to add via controller, then the best alternative is to add via the XML.However the question that will arise is how i would obtain the name of the reference to attach my button to.

i.e this is an example of adding the button to the products grid. the reference name is products_list.But how would i obtain the reference name for my custom modules grid?

Code: Select all
<reference name="products_list">
      <action method="addButton">
                <label>My button</label>