Here, how to add new action in grid like ‘Edit’ link at admin grid.
On this example, we will add a “schedule” action in product admin grid.
We will overrite this class /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php.
Declare the rewrite class on the /app/code/local/Adin/Catalog/etc/config.xml
and add
1 2 3 4 5 6 7 8 9 | < global > < blocks > < adminhtml > < rewrite > < catalog_product_grid >Adin_Catalog_Block_Adminhtml_Catalog_Product_Grid</ catalog_product_grid > </ rewrite > </ adminhtml > </ blocks > </ global > |
Then create your rewritted class /app/code/local/Adin/Catalog/Block/Adminhtml/Catalog/Product/Grid.php.
1 2 3 4 | <?php class Adin_Catalog_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid { } ?> |
Now, rewrite the _prepareColumns() function, find the ‘action’ column an add an entry in the actions array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | $this ->addColumn( 'action' , array ( 'header' => Mage::helper( 'catalog' )->__( 'Action' ), 'width' => '50px' , 'type' => 'action' , 'getter' => 'getId' , 'actions' => array ( array ( 'caption' => Mage::helper( 'catalog' )->__( 'Edit' ), 'url' => array ( 'base' => '*/*/edit' , 'params' => array ( 'store' => $this ->getRequest()->getParam( 'store' )) ), 'field' => 'id' ), array ( 'caption' => Mage::helper( 'catalog' )->__( 'Schedule' ), 'url' => array ( 'base' => '*/*/schedule' , 'params' => array ( 'store' => $this ->getRequest()->getParam( 'store' )) ), 'field' => 'id' ), ), 'filter' => false, 'sortable' => false, 'index' => 'stores' , )); |
In our example, we just add this part
1 2 3 4 5 6 7 8 | array ( 'caption' => Mage::helper( 'catalog' )->__( 'Schedule' ), 'url' => array ( 'base' => '*/*/schedule' , 'params' => array ( 'store' => $this ->getRequest()->getParam( 'store' )) ), 'field' => 'id' ), |
One last thing, at the end of the _prepareColumns function, change
1 | return parent::_prepareColumns(); |
by
1 | return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns(); |