public function beforeAction($action)
 {
     if (($params = $this->params) === null) {
         $request = Yii::$app->getRequest();
         $params = $request instanceof Request ? $request->post() : [];
     }
     if (isset($params[$this->clearStateParam]) && $params[$this->clearStateParam] != '0') {
         FilterStateTrait::clearFilterStateParams($this->id);
         if (Yii::$app->request->getIsAjax() && $this->exitIfAjax) {
             Yii::$app->end();
         } else {
             $redirectTo = isset($params[$this->redirectToParam]) ? $params[$this->redirectToParam] : Yii::$app->controller->getRoute();
             Yii::$app->response->redirect($redirectTo);
         }
         return false;
     }
     return true;
 }
 public function saveState()
 {
     $session = Yii::$app->session;
     /** @var \yii\grid\GridView $gridView */
     $this->_gridView = $gridView = $this->owner;
     $this->_state = FilterStateTrait::getFilterStateParams($this->id);
     // Filter
     /** @var \yii\grid\DataColumn $column */
     foreach ($gridView->columns as $column) {
         if (!$column instanceof DataColumn) {
             continue;
         }
         if ($column->filter !== false) {
             $this->composeFilterState($column);
         }
     }
     // Sort
     if ($gridView->dataProvider->getSort() !== false) {
         $sort = $gridView->dataProvider->getSort();
         if (($sortValue = ArrayHelper::getValue($sort->params, $sort->sortParam)) !== null) {
             $this->_state[$sort->sortParam] = $sortValue;
         } else {
             unset($this->_state[$sort->sortParam]);
         }
     }
     // Pagination
     if ($gridView->dataProvider->getPagination() !== false) {
         $pagination = $gridView->dataProvider->getPagination();
         if (($pageValue = ArrayHelper::getValue($pagination->params, $pagination->pageParam)) !== null) {
             $this->_state[$pagination->pageParam] = $pageValue;
         } else {
             unset($this->_state[$pagination->pageParam]);
         }
         if (($pageSizeValue = ArrayHelper::getValue($pagination->params, $pagination->pageSizeParam)) !== null) {
             $this->_state[$pagination->pageSizeParam] = $pageSizeValue;
         } else {
             unset($this->_state[$pagination->pageSizeParam]);
         }
     }
     $session->set(static::buildKey($this->id), $this->_state);
 }