B-219 Sec-55 Noida, India

Magento: How to search or filter by multiselect attribute in admin grid

Suppose you have a multi select attribute and you have displayed it in admin grid. You have displayed the multi select attribute options as selection list. Now, you want to filter/search the grid by the multiselect attribute.

The problem here is that the multiselect attribute value is store as comma separated value in database. When we send single value from the selection list, the filter doesn’t work properly.

The solution is to use filter_condition_callback in addColumn.

Here is the code:-
                    ‘header’=> Mage::helper(‘mymodule’)->__(‘Categories’),
                    ‘index’ => ‘categories’,
                    ‘width’ => ‘150px’,
                    ‘type’ => ‘options’,
                    ‘options’ => $categories,
                                => array($this, ‘_filterCategoriesCondition’),

The callback function is:-
protected function _filterCategoriesCondition($collection, $column)
    if (!$value = $column->getFilter()->getValue()) {

    $this->getCollection()->addFieldToFilter(‘categories’, array(‘finset’ => $value));

The similar thing is done in Mage_Adminhtml_Block_Cms_Block_Grid class to filter Store View.

Hope this helps. Thanks.

(Visited 116 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.