Magento Custom Grid delete action not working

Magento Custom Grid delete action not working

September 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Custom Grid delete action not working

Solving Delete Actions in Magento Custom Grids

Are you struggling with deleting items from your custom Magento grid? You’re not alone. Many developers face issues when trying to implement delete actions for their grids. Let’s dive into the solution and address the common pitfalls.

Understanding the Delete Action Structure

In Magento, the delete action is handled by the Mage_Adminhtml_Controller_Action class. To create a custom delete action, you need to extend this controller and override the deleteAction() method in your module’s controller.

Setting Up Your Controller

Let’s assume you have a custom grid for managing products with a model named Your_Product_Model. Here’s how you should structure your controller:

class Your_Adminhtml_ProductController extends Mage_Adminhtml_Controller_Action
{
    public function deleteAction()
    {
        $id = $this->getRequest()->getParam('product_id');
        $model = Mage::getModel('your_product_model/your_product');

        if ($id) {
            try {
                $model->setId($id)->delete();
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('your_helper')->__('Product deleted successfully'));
                $this->_redirect('*/*/');
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('id' => $id));
            }
        }
    }
}

Configuring Your Grid Column

You mentioned that you have already added the action column to your grid. However, there’s a slight issue with the configuration.

array(
    'url'       => array('base'=> '*/*/delete'),
    'field'     => 'id'
)

The issue lies in the URL. In Magento, the base URL for your controller actions should be prefixed with the module name and without any slashes.

Correcting the Action Column Configuration

Here’s how you should configure your action column:

array(
    'url'       => array('base'=> 'your/your_product/delete'),
    'field'     => 'product_id'
)

Notice that we’re using the correct module name your and the controller action. We’ve also changed the field to match our parameter name (product_id).

Ensuring Security Checks

Magento performs several security checks before allowing a delete action. Ensure that your user is allowed to perform the action by using the following code in your constructor:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('your/your_product');
}

Conclusion

Deleting items from custom Magento grids requires a careful setup of your controller and grid column configuration. Ensure you’re extending the correct base class, overriding the delete method correctly, configuring your URL in the action column, and checking for security permissions.

Remember to replace your with your actual module name throughout the code samples.

If you’re facing any other challenges with Magento development or want to learn more about advanced techniques, check out our blog at https://laravelcompany.com. We regularly publish articles on Magento best practices and tips from experienced developers.

Catalog Extensions Admin Configuration

Our network