Magento Grid : Better way of using addColumn Actions?

Magento Grid : Better way of using addColumn Actions?

August 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Grid : Better way of using addColumn Actions?

Solving the Magento Grid Delete Action Parameter Issue

The Problem: Missing Filename Parameter in Magento Grid Delete Action

In your Magento grid setup, you’ve configured a ‘Delete’ action for each file listed in the grid view. However, when you click the “Delete” button, the filename parameter is not being passed to the deleteAction method of your controller.

The current implementation looks like this:

'params' => array('filename' => 'TESTDUMP')

The params option inside the url array is used to pass additional parameters when executing the URL. However, in the current code, the TESTDUMP value is hardcoded and does not reflect the actual filename of the selected item.

The Controller: Rogue_Googlemerchant_Adminhtml_ExporterController

The deleteAction method in your controller is defined as follows:

public function deleteAction()
{
    $filename = $this->getRequest()->getParam('filename');
    // ...
}

The getRequest()->getParam('filename') line is supposed to retrieve the filename parameter passed from the grid view. However, since the params option in your grid setup does not pass the actual filename, this line always returns null.

The Solution: Properly Setting Up Grid Columns and Actions

To properly set up the ‘Delete’ action for each item in the grid, you should use the getUrl('*/*/delete', array('filename' => $this->escapeHtml($item->getFilename()))) syntax.

Your _prepareColumns method in the Rogue_Googlemerchant_Block_Adminhtml_Exporter_Grid block should look like this:

protected function _prepareColumns()
{
    // ...
    $this->addColumn('action', array(
        'header' => Mage::helper('googlemerchant')->__('Action'),
        'width'  => '50px',
        'type'   => 'action',
        'actions' => array(
            array(
                'caption' => Mage::helper('googlemerchant')->__('Delete'),
                'url'     => array(
                    'base'   => '*/*/delete',
                    'params' => array($this->escapeHtml($item->getFilename()))
                )
            )
        ),
        // ...
    ));
}

In this updated code, the getUrl method is used to generate a URL for each delete action. The second parameter of the getUrl method is an array containing the filename as its key-value pair.

The escapeHtml($item->getFilename()) ensures that any special characters in the filename are properly encoded before being passed as a parameter.

Conclusion: Resolving the Delete Action Parameter Issue

By correctly setting up the grid columns and actions, you ensure that the actual filename of each item is passed to the deleteAction method of your controller when the “Delete” button is clicked.

Remember that the getRequest()->getParam('filename') line in your deleteAction method will now retrieve the correct filename parameter thanks to this change.

The key takeaway is to always use the getUrl method with the appropriate parameters when setting up actions in a Magento grid. This ensures that the necessary data is properly passed between the front-end and back-end components of your system.

For more detailed information on working with Magento grids and controllers, I recommend checking out our comprehensive guide at https://laravelcompany.com/magento-development/grid-controller-communication.

By following these best practices, you can achieve proper communication between your grid views and corresponding controller actions in Magento.

Admin Configuration Pricing Import/Export

Our network