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.

//controller




$searchModel = new EnrolmentHistorySearch();

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

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

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);



//model




$query = EnrolmentHistory::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

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

        ]);


        $this->load($params);


        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;

        }


        $query->andFilterWhere([

            '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'],

            'eh_id',


            ['attribute'=>'eh_enrolment','format'=>'raw','value'=>function($data){

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


            }],

            //'eh_enrolment',

            'eh_user',


             ['attribute'=>'eh_desc','format'=>'html','value'=>function($data){

                return $data->eh_desc;


            }],


            //'eh_desc:ntext',

            'eh_file',

            'enrolment.internal_status',


            'eh_datetime',

            ['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?