magento show content according to condition in admin grid

magento show content according to condition in admin grid

October 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento show content according to condition in admin grid

Customizing Magento Admin Grid Data According to Conditions

As an experienced Magento developer, you may find yourself needing to display data in your admin grid according to specific conditions. This often requires customization of the collection data before it reaches the grid and tailoring the column output based on certain rules.

Understanding the Current Implementation

In your current module, you’re using the standard _prepareCollection and _prepareColumns methods to populate the grid with data from a wallets/sellerrequest collection. You’ve also joined customer entity data for seller names using Magento’s EAV system.

The _prepareColumns method defines the columns that will appear in the grid, including ‘id’, ‘Requested Amount’, ‘Seller Name’, and ‘Status’. Currently, these values are simply pulled from the database fields directly without any additional processing or formatting.

Formatting Requested Amount

To display the requested amount with a leading dollar sign ($), you can easily modify the column definition in _prepareColumns. Update the relevant line as follows:

$this->addColumn('Requested Amount', array(
    'header' => $helper->__('Requested Amount'),
    'index'  => 'request_amount',
    'type'  => 'price',
));

The type option is set to 'price', which tells Magento to format the value as a currency. By default, this will add a dollar sign ($) before the amount.

Conditionally Formatting Status Flag

For handling the status flag conditionally (e.g., “Approved” for 1, “Pending” for 2), you’ll need to override the grid block’s _prepareColumns method and add custom formatting logic. Here’s how:

  1. Create a new file at app/code/local/YOUR_PACKAGE/NAMESPACE/Block/Adminhtml/Sellerrequest/Grid.php.

  2. Extend the core Magento _prepareColumns method with your own implementation:

class YOUREXTENSIONS_Adminhtml_Sellerrequest_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    // Override the original method to add custom logic for status flag formatting

    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumn('Status', array(
            'header'        => $helper->__('Status'),
            'index'         => 'status_flag',
            'type'          => 'options',
            'options'       => array( 
                1 => 'Approved',
                2 => 'Pending',
            ),
        ));
    }

    // Rest of the class remains unchanged

}

In this code, we’re extending the Mage_Adminhtml_Block_Widget_Grid class and overriding the _prepareColumns method. The 'Status' column is defined with a 'type' => 'options' to allow custom options for each possible flag value.

Conclusion and Further Reading

By following these steps, you should now be able to display your requested amount with a leading dollar sign ($) in the admin grid and format status flags conditionally. This approach demonstrates how to customize Magento’s built-in functionality using best practices for extension development.

For more detailed information on Magento grid customization, I recommend checking out our comprehensive guide at Laravel Company.

Database Extensions Admin Customers

Our network