filter disappear in paginations

Hi, I got a search filter which works fine in the first page, but in the second page filter params disappear therefore it gives incorrect result.


$searchModel = new EnrolmentHistorySearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,



$query = EnrolmentHistory::find();

        $dataProvider = new ActiveDataProvider([

            'query' => $query,

            'sort'=> ['defaultOrder' => ['eh_id'=>SORT_DESC]]



        if (!$this->validate()) {

            // uncomment the following line if you do not want to return any records when validation fails

            // $query->where('0=1');

            return $dataProvider;



            'eh_id' => $this->eh_id,

            'eh_enrolment' => $this->eh_enrolment,

            'eh_datetime' => $this->eh_datetime,


        $query->andFilterWhere(['like', 'eh_user', $this->eh_user])

            ->andFilterWhere(['like', 'eh_desc', $this->eh_desc])

            ->andFilterWhere(['like', 'eh_file', $this->eh_file]);

        return $dataProvider;

I see nothing strange so far.

Could you show us your view file?

Thanks for the reply.

Here is view code

<?= GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],



                return Html::a('view', ['enrolment/view', 'id' => $data->eh_enrolment]);





                return $data->eh_desc;






            ['class' => 'yii\grid\ActionColumn','template'=>'{view}']


    ]); ?>

I still don’t see anything strange.

Do you come to the second page using the pager of the grid view?

Do you mean that the page works fine with its filtering functionality, but once you click the pager the filtering parameters get reset?