this is part of controller action
$searchModelSuperior = new KakitanganSearch();
$dataProviderSuperior = $searchModelSuperior->search(Yii::$app->request->queryParams, 1);
$dataProviderSuperior->pagination->pageParam = 'superior-page';
$dataProviderSuperior->sort->sortParam = 'superior-sort';
$searchModelSubordinate = new KakitanganSearch();
$dataProviderSubordinate = $searchModelSubordinate->search(Yii::$app->request->queryParams, 2);
$dataProviderSubordinate->pagination->pageParam = 'subordinate-page';
$dataProviderSubordinate->sort->sortParam = 'subordinate-sort';
$searchModelAvailableStaff = new KakitanganSearch();
$dataProviderAvailableStaff = $searchModelAvailableStaff->search(Yii::$app->request->queryParams, 3);
$dataProviderAvailableStaff->pagination->pageParam = 'availableStaff-page';
$dataProviderAvailableStaff->sort->sortParam = 'availableStaff-sort';
The reason i use different search model variable, as u can see above, i add parameter value (1, 2 or 3) to search function. Depend on the value, an if statement will add the required andFilterWhere in the search class so that each gridview will obtain specific record.
Here is code for my gridview
<h2><?= Yii::t('app', 'Supervisor') ?></h2>
<?= GridView::widget([
'id' => 'grid1',
'dataProvider' => $dataProviderSuperior,
'filterModel' => $searchModelSuperior,
// 'filterRowOptions' => ['name' => 'KakitanganSearch1'],
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'nama',
'namapanggilan',
'nokp',
[
'attribute' => 'jawatan',
'value' => 'fkJawatan.nama',
'label' => Yii::t('app', 'Position'),
],
'status',
[
'attribute' => 'createByUser',
'value' => 'createdBy.username',
'label' => Yii::t('app', 'Created By'),
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<h3><?= Yii::t('app', 'Subordinate') ?></h3>
<?= GridView::widget([
'id' => 'grid2',
'dataProvider' => $dataProviderSubordinate,
'filterModel' => $searchModelSubordinate,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'nama',
'namapanggilan',
'nokp',
[
'attribute' => 'jawatan',
'value' => 'fkJawatan.nama',
'label' => Yii::t('app', 'Position'),
],
'status',
[
'attribute' => 'createByUser',
'value' => 'createdBy.username',
'label' => Yii::t('app', 'Created By'),
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<h2><?= Yii::t('app', 'Staff without supervisor') ?></h2>
<?= GridView::widget([
'id' => 'grid3',
'dataProvider' => $dataProviderAvailableStaff,
'filterModel' => $searchModelAvailableStaff,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'nama',
'namapanggilan',
'nokp',
[
'attribute' => 'jawatan',
'value' => 'fkJawatan.nama',
'label' => Yii::t('app', 'Position'),
],
'status',
[
'attribute' => 'createByUser',
'value' => 'createdBy.username',
'label' => Yii::t('app', 'Created By'),
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>