4

How do I retrieve the grid filters in an observer?

public function beforeCollectionLoad(Varien_Event_Observer $observer)
{
    $collection = $observer->getCollection();

    if (!isset($collection)) {
        return;
    }

    //get filter here
    //normally:
    //$filter = $this->getParam($this->getVarNameFilter(), null);
}
  • which observer are you using? – Amit Bera Jul 7 '15 at 10:04
  • eav_collection_abstract_load_before – user1240207 Jul 7 '15 at 10:06
2

when you have a grid object you can retrieve the filter array like this :

public function __construct()
{
    parent::__construct();
    $this->setId('GridId');
    $this->setTemplate('../../..phtml');
    $this->setSaveParametersInSession(true);
    $this->setUseAjax(true);
    $this->setVarNameFilter('_filter'); 
}

$filter = $this->getParam('_filter');
$filter_data = Mage::helper('adminhtml')->prepareFilterString($filter);                   
print_r($filter_data);

From a column, it's possible like this :

$filter = $this->getColumn()->getGrid()->getParam('_filter');
$filter_data = Mage::helper('adminhtml')->prepareFilterString($filter);                   
print_r($filter_data);

For the observer, you can do this

Hope this help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.