A
A
AlexSer2018-11-17 17:26:41
Yii
AlexSer, 2018-11-17 17:26:41

Is it possible to set the columns in some way through the Yii2 Gridview parameter?

Tell me please! I send an Ajax request to the controller, depending on the parameter, the controller accesses the corresponding model, respectively, the columns change when the gridview is displayed. Is it possible to set a condition, in Gridview, so that the choice of columns depends on the selected model.

'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        [

            'attribute'=>'sid',
            'label' => 'Номер отправки',

        ],
        [

            'attribute'=>'ts',
            'label' => 'Время',

        ],
]

For example, if the Gridview does not see the ts column, then show another column! something like this...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-11-18
@AlexSer

Of course you can. Columns are an array. You can form an array as you like and pass it to the widget as a variable.
In some cases, this may be a method in the model, for example, in the search model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question