Magento 1.8 Custom Module – How to Reset Filter on Loading a Collection

gridmagento-1.8reset-filter

I have created a custom module in backend to display the search results of 'imei' in admin grid.

1) below is the home page to search imei.
enter image description here

2) search result page.

enter image description here

3) after searching i enter the value say for example 23 in imei text field search.
enter image description here

4)now i going back to home page and searching another value.

enter image description here

5)but now i get no records found, but there is records for that particular search.

enter image description here

since this happens, i have to reset filter on loading collection.

Best Answer

Edit grid.php file in your custom module,

By default,

public function __construct()
{
 parent::__construct();
 $this->setId('productsGrid');
 // This is the primary key of the database
 $this->setDefaultSort('id');
 $this->setDefaultDir('ASC');
 $this->setSaveParametersInSession(true);
 $this->setUseAjax(true);
}

Change the code to,

public function __construct()
{
    parent::__construct();
    $this->setId('productsGrid');
    // This is the primary key of the database
    $this->setDefaultSort('id');
    $this->setDefaultDir('ASC');
    $this->setUseAjax(true);
}