protected function _prepareCollection() { $collection = Mage::getModel('my_extension/model')->getCollection(); $this->setCollection($collection); parent::_prepareCollection(); $this->getCollection()->addAttributeToSelect('*'); if ($this->getRequest()->getParam('my_column')) { $this->getCollection()->addFieldToFilter('my_column', $this->getRequest()->getParam('my_column')); } return $this; }
public function _addColumnFilterToCollection($column) { if ($column->getId() == 'status') { $collection = $this->getCollection(); $value = $column->getFilter()->getValue(); if ($value == 'active') { $this->getCollection()->addFieldToFilter('status', true); } elseif ($value == 'inactive') { $this->getCollection()->addFieldToFilter('status', false); } } else { parent::_addColumnFilterToCollection($column); } return $this; }In this example, we are overriding the _addColumnFilterToCollection method to add custom filtering logic for a specific column ('status'). If the user selects the 'active' filter option, we add a where clause to only include records where the status field is true. If the user selects 'inactive', we include only records where the status field is false. For all other columns, we call the parent method to handle filtering as usual.