I have found a solution. Before attaching it to a GridView, you need to find a regular model. So I just need to add one line to make it work:
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
All code would like this:
<?php
$searchModel = New CitySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'city_name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Pawan source
share