Magento 2, Magento Admin, Magento basic, Magento2.2

How to unset the Filter in Magento 2 admin Grid:

When use the same admin grid collection into more than once place the main grid session will keep on maintain to other places also. When you filter the result from Main table, the same filter result automatically reflect into other place where use the same collection grid. To avoid this we can reset the filter based on the page where you use.

Ex: Consider we have created one module with admin grid collection (Ex: M1). The same collection we have used for some other Grid (Ex: M2). When you filter by some column field the same filter result automatically affect into M2 grid also because same collection result. To avoid we need to reset the filter based on the page or controller action .
File path for M1 : Jute\Ecommerce\Block\Adminhtml\Mobiletype\Edit\Tab\Mobiletype1.php

protected function _construct() {
 parent::_construct();
 $this->setId('mobiletypeGrid');
 $this->setDefaultSort('mobile_id');
 $this->setDefaultDir('ASC');
 $this->setSaveParametersInSession(true);
 $this->setUseAjax(true);
 }

File path for M2 : Jute\Ecommerce\Block\Adminhtml\Mobiletype\Edit\Tab\Mobiletype2.php

protected function _construct() {
 parent::_construct();
 $this->setId('mobiletypeGrid');
 $this->setDefaultSort('mobile_id');
 $this->setDefaultDir('ASC');
 $this->setUseAjax(true);
 if (<PAGE CONTROLLER ACTION == '<MYCUSTOMCONTROLLER>'>) {
 $this->setSaveParametersInSession(false);
 }else{
 $this->setSaveParametersInSession(true);
 }
 }
Advertisements