Magento: Show different action links in on column in the backend data grid

Magento: Show different action links in on column in the backend data grid

July 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Show different action links in on column in the backend data grid

Showing Different Action Links on the Same Column in Magento Backend Data Grid

Working with custom product lists in the Magento backend can be quite challenging when you want to display different action links based on certain conditions. In this post, we’ll explore how to achieve this without resorting to complex workarounds.

Currently, you’re able to add an “Action” column to your grid using code similar to the following:

// Column definition
$this->addColumn('action_widget',
    array(
        'header' => Mage::helper('catalog')->__('Action'),
        'width' => '110px',
        'type' => 'action',
        'getter' => 'getId',
        'actions' => array(
            array(
                'caption' => Mage::helper('catalog')->__('Create Widget'),
                'url' => array(
                    'base' => '*/*/create_widget',
                    'params' => array('store' => $this->getRequest()->getParam('store'))
                ),
                'field' => 'id'
            )
        ),
        'filter' => false,
        'sortable' => false,
        'index' => 'stores',
    )
);

This works perfectly for a single action link. However, you want to display an “Update Widget” link instead of the “Create Widget” link when the widget already exists.

To accomplish this, we can leverage Magento’s built-in ability to conditionally render links based on data associated with the collection item. Here’s how:

  1. Join your necessary collection: First, ensure you have joined your required attribute (that indicates whether a widget is created or not) to your main product collection. You’ve already mentioned you’re joining an attribute that is null when it doesn’t exist and is a string when it does.

  2. Customize the actions array: Instead of a single action array, create two separate arrays - one for the “Create” link and another for the “Update” link. Then, use conditional logic to determine which array to return based on your joined attribute data.

Here’s an example:

$actionArray = array();
if ($this->getData('your_attribute') === null) {
    $actionArray['create'] = array(
        'caption' => Mage::helper('catalog')->__('Create Widget'),
        // Rest of the create action array...
    );
} else {
    $actionArray['update'] = array(
        'caption' => Mage::helper('catalog')->__('Update Widget'),
        // Rest of the update action array...
    );
}

// Add column with custom actions
$this->addColumn('action_widget',
    array(
        'header' => Mage::helper('catalog')->__('Action'),
        'width' => '110px',
        'type' => 'action',
        'getter' => 'getId',
        'actions' => $actionArray, // Pass the conditional action array
        'filter' => false,
        'sortable' => false,
        'index' => 'stores',
    )
);
  1. Update your grid template: In your custom grid template file (usually located under app/design/frontend/base/default/template/catalog/product_grid.phtml), you can add custom logic to handle the different action links. Use PHP heredoc syntax within your HTML content to check if a specific link exists and display it accordingly.

Remember, Magento’s URL validation may still prevent certain actions based on its built-in rules, but this approach provides a cleaner solution than trying to assign variables directly in the URL.

For more advanced customizations, consider exploring the options provided by Magento Company, which specializes in complex backend modifications and extensions for Magento. Their expertise can help you tackle even more challenging requirements with your product lists.

In conclusion, showing different action links on a single column in the Magento backend data grid is possible with careful collection manipulation and conditional logic within your custom grid code. By leveraging existing features and avoiding unnecessary workarounds, you can achieve the desired behavior efficiently.

Catalog Database Admin

Our network