can't Filter or search product in grid with custom renderer

can't Filter or search product in grid with custom renderer

September 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
can't Filter or search product in grid with custom renderer

Solving Filter Issues for Custom Renderer Columns in Magento Admin Grid

As an experienced developer working with Magento admin grids, I’ve encountered this common issue: filters not working for columns that use custom renderers. In your case, you’re trying to filter the ‘order_item_id’ column which is rendered as the product name through a renderer class.

The problem lies in how you’ve configured the filter callback function. Let’s dive into the solution step by step.

Understanding the Issue

You’ve correctly set up the column definition with the appropriate renderer and filter condition callback:

$this->addColumn('order_item_id', array(
    'header' => Mage::helper('adminhtml')->__('Product Name'),
    'align' => 'right',
    'index' => 'order_item_id',
    'renderer' => 'Test_Module1_Block_Adminhtml_Renderer_Product',
    'filter_condition_callback' => array($this, '_productFilter'),
));

The issue arises in how you’re handling the filter condition callback. In your _productFilter method:

protected function _productFilter($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    $this->getCollection()->getSelect()->where(
        "order_item_id like ?"
    , "%$value%");

    return $this;
}

You’re attempting to filter the ‘order_item_id’ column directly, which is causing the issue. Since you’re rendering the product name from another table (‘sales/order_item’), you need to join this table and apply the filter on its appropriate field.

The Correct Approach

To fix this, we need to modify both the column definition and the filter condition callback:

  1. Update your _prepareColumns method:
public function _prepareColumns()
{
    // Other columns...

    $this->addColumn('order_item_id', array(
        'header' => Mage::helper('adminhtml')->__('Product Name'),
        'align' => 'right',
        'index' => 'order_item_id',
        'renderer' => 'Test_Module1_Block_Adminhtml_Renderer_Product',
        'filter_condition_callback' => array($this, '_productFilter'),
    ));

    return parent::_prepareColumns();
}
  1. Update your _productFilter method:
protected function _productFilter($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    // Join the 'sales/order_item' table and filter on its 'name' field
    $collection->getSelect()
        ->join(
            array('item' => 'sales/order_item'),
            "main_table.order_item_id = item.item_id",
            array('name')
        )
        ->where("item.name like ?", "%$value%");

    return $this;
}

Key Changes and Best Practices

In the updated code:

  • We’ve joined the ‘sales/order_item’ table to our main collection.
  • The filter is now applied on the appropriate field (item.name) from the joined table.

Remember these best practices when working with custom renderer columns in Magento admin grids:

  1. Always ensure you’re applying filters on the correct fields, especially when dealing with joined tables.
  2. Use the proper join conditions to connect your main collection with other necessary tables.
  3. Regularly test your grid functionality, including filtering and pagination.

Conclusion

In summary, fixing filter issues for custom renderer columns in Magento admin grids requires a deep understanding of how data is structured across multiple tables and how filters are applied through the joined fields.

By updating both the column definition and the filter condition callback method, you’ve successfully resolved your issue. The updated code correctly joins the necessary table (‘sales/order_item’) and applies the filter on its appropriate field (name).

Remember to always test your changes thoroughly after making updates like these. Proper testing ensures that your admin grid maintains optimal performance and user experience.

For more detailed guides on working with Magento admin grids, visit our website at https://laravelcompany.com/magento-admin-grids-guide.

Catalog Database Extensions Admin

Our network