Need a hint. I master Yii2 and there was a problem. There is a table USER and GridView with data from this table - filtering works. And there is a table SEND and GridView with data from this table - here it does not perform filtering. The code was taken from the User class and SearchUser.

CONTROLLER

public function actionAllsend(){ if(isAdmin()){ $searchModel = new SendSearch(); //ΠŸΠΎΠ»ΡƒΡ‡ΠΈΠΌ записи ΠΏΠΎ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΌΡƒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŽ $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('allsend', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } else{ return $this->redirect(['site/index']); } } 

MODEL

 public function search($params, $userName = null) { $this->load($params); // ΠŸΠΎΠ»ΡƒΡ‡ΠΈΠΌ всС записи Π»ΠΈΠ±ΠΎ записи ΠΏΠΎ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΌΡƒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŽ if($userName == null){ $query = Send::find(); // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, ]); $query->andFilterWhere(['like', 'user_id', $this->user_id]) ->andFilterWhere(['like', 'type', $this->type]) ->andFilterWhere(['like', 'date', $this->date]) ->andFilterWhere(['like', 'status', $this->status]); } else{ $query = Send::find(); $query->andFilterWhere([ 'user_id' => $userName, ]); } // echo $query; $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'forcePageParam' => false, 'pageSizeParam' => false, 'pageSize' => 20 ] ]); 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; } return $dataProvider; } 

VYUHA

 <div class="admin-all-send"> <h1><?= Html::encode($this->title) ?></h1> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ //['class' => 'yii\grid\SerialColumn'], ['attribute'=>'id', "label"=>'Π£Π½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΉ Π½ΠΎΠΌΠ΅Ρ€ рассылки'], ['attribute'=>'date', "label"=>'Π”Π°Ρ‚Π° Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ'], ['attribute'=>'user_id', 'label'=>'Чья рассылка'], ['attribute'=>'type', 'label'=>'Π’ΠΈΠΏ рассылки'], ['attribute'=>'status', "label" => "Бтатус рассылки"], ['attribute'=>'price', 'label'=>'Π¦Π΅Π½Π° рассылки'], ['class' => 'yii\grid\ActionColumn', 'template' => '{view} {delete}', ], ], ]); ?> </div> 

    1 answer 1

    Found a problem. Jamb in the model was. So work:

     public function search($params, $userName = null) { $this->load($params); // ΠŸΠΎΠ»ΡƒΡ‡ΠΈΠΌ всС записи Π»ΠΈΠ±ΠΎ записи ΠΏΠΎ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΌΡƒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŽ if($userName == null){ $query = Send::find(); // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, ]); } else{ $query = Send::find(); $query->andFilterWhere([ 'user_id' => $userName, ]); } $query->andFilterWhere(['like', 'user_id', $this->user_id]) ->andFilterWhere(['like', 'type', $this->type]) ->andFilterWhere(['like', 'date', $this->date]) ->andFilterWhere(['like', 'status', $this->status]); // echo $query; $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'forcePageParam' => false, 'pageSizeParam' => false, 'pageSize' => 20 ] ]); 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; } return $dataProvider; }