How do I use the 'concat' type in the addColumn() method when building a grid?

How do I use the 'concat' type in the addColumn() method when building a grid?

August 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I use the 'concat' type in the addColumn() method when building a grid?

Using the ‘concat’ Type in Magento’s addColumn() Method

The Mage/Adminhtml/Widget/Grid/Column/Renderer/Concat.php class is a built-in Magento extension that allows you to concatenate multiple values into a single column in your grid. It provides a convenient way to combine data from different tables or columns without having to write complex SQL queries.

In the provided example, the developer is using raw SQL within the filter_index parameter of the addColumn() method to concatenate two fields: orders.increment_id and main_table.item_id. This approach works but isn’t the most efficient or maintainable way to handle such concatenations.

Implementing the Concat Renderer

To use the Concat renderer, you need to specify it in your addColumn() configuration. Here’s an example of how you can modify the given code:

$this->addColumn(
    'order_item',
    [
        'header' => $this->__('Order # (Item #)'),
        'sortable' => true,
        'index' => 'order_item',
        'filter_index' => 'CONCAT(main_table.order_id, \'(main_table.item_id)\')', // Use concatenation
        'renderer' => Mage::getSingleton('adminhtml/widget_grid_column_renderer_concat'), // Specify the renderer
        'width' => '140px',
    ]
);

In this example, I’ve replaced the raw SQL in filter_index with a simple concatenation using backticks (“) to wrap the values. Then, I added the 'renderer' parameter and set it to an instance of the Mage::getSingleton('adminhtml/widget_grid_column_renderer_concat').

Benefits of Using the Concat Renderer

Using the Concat renderer provides several advantages:

  1. Code Clarity: It separates the concatenation logic from the SQL query, making your grid setup cleaner and easier to read.

  2. Flexibility: You can easily add or remove values in the concatenated string without changing the SQL query itself.

  3. Performance: While this might seem minor, using a renderer instead of raw SQL could potentially improve performance by reducing the complexity of the generated SQL queries.

  4. Maintainability: If you need to make changes to your grid later on, it’s much easier to modify the concatenated string in one place rather than updating multiple SQL queries.

For more detailed information about working with Magento grids and renderers, I recommend checking out our comprehensive guide on Magento Grid Configuration.

Conclusion

The Concat renderer is a powerful tool for handling concatenated columns in your Magento grids. By properly integrating it into your grid setup, you can achieve cleaner, more maintainable code and potentially improve the performance of your admin panel.

Remember to always test your changes thoroughly, especially when working with data manipulation methods like this one. Happy coding!

Database Extensions Admin Configuration

Our network