Yii2 user grid filter by role

Hello Friends,

i have multiple role in my application i want to add filter by role in user grid.

i have used default yii2 advance template user table and rbac table.

in my controller


public function actionIndex()

     {

        $searchModel = new UserSearch();

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

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

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

     }



in my view file


<?php echo GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'options' => [

            'class' => 'grid-view table-responsive'

        ],

        'columns' => [

            'id',

            'username',

            'email:email',

            [

                'class' => EnumColumn::className(),

                'attribute' => 'status',

                'enum' => User::statuses(),

                'filter' => User::statuses()

            ],

            'created_at:datetime',

            'logged_at:datetime',

            // 'updated_at',


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

        ],

    ]); ?>

how can i add filter by role in user grid.

i have five table to accomplish this

user

auth_assignment

auth_item

auth_item_child

auth_rule

any one have developed this type of grid…?? please help

Its very simple one like

i have bind query in UserSearch model like…


if($this->role){

      $query->join('LEFT JOIN','rbac_auth_assignment','rbac_auth_assignment.user_id = id')

      ->andFilterWhere(['rbac_auth_assignment.item_name' => $this->role]);

 }

its working fine. :)