K
K
Kurper2019-08-08 15:45:38
Yii
Kurper, 2019-08-08 15:45:38

What is the best way to manage GridView from the admin panel?

Hello.
There was a need to customize the GridView for different roles and for different users. For example, we have a certain table "goods" that can be viewed by users such as managers, a storekeeper ...
For a manager, I want to show all columns, but for a storekeeper, not all columns are important and I will show only the number and name of the product. I want to do this not for one table, but for many and adjust the visibility of columns from the admin panel. Who can advise me? Maybe someone has already done such a task, what is the best way to do it? Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-08-08
@Kurper

Permissions are made using RBAC, which is available in Yii2. You can implement your own logic. In order to be able to change the data, it is better to store them in the database. RBAC Yii2 allows this.
The display of columns is provided by the "visible" property in GridView. It needs to be passed a boolean value (false, true)
“visible” => true // or your condition

[
    'label' => 'Executive Name',
    'attribute' => 'cs.first_name',
    'visible' => function ($data) {
        if ($data->hc_customersupport->is_supervisor) {
            return '1'; // or return true;
        } else {
            return '0'; // or return false;
        }
    },
],

use Yii;

...

'visible' => Yii::$app->user->can('supervisor'),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question