showing user roles (rbac) in a searchable / sortable gridview column in yii2

148 views Asked by At

I have a gridview widget which shows my user roles like so:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ...
        [
            'header' => 'roles',
            'content' => function ($model, $key, $index, $column){
                $auth = Yii::$app->authManager;
                $roles = $auth->getRolesByUser($model->id);
                $string = ' ';
                foreach ($roles as $role) {
                    $string .= $role->name . " ";
                }
                return $string;
            }
        ],
        ...
        [
            'class' => 'yii\grid\ActionColumn'
        ],
    ],
]); ?>

How can I make this column sortable and searchable? Any ideas or suggestions would be greatly appreciated

0

There are 0 answers