there is such a code

if(is_array($color)){$colorDatas=ArrayHelper::map($color,'id','value');} 

now I need if $ colorDatas is not empty I need to add the following widget to the 'columns'

 [ 'filter' =>Select2::widget ([ 'model' => $searchModel, 'attribute' => 'color', 'data' => $colorDatas, 'language' => 'ru', 'options' => ['multiple' => true,'placeholder' => Yii::t('backend','SELECT_SHOP')], 'pluginOptions' => [ 'allowClear' => true ], ]), 'attribute' => 'color', 'value' => function($model){ return $model->theGetValue($model); } ], 

in GridView do not tell me how to do it

    1 answer 1

    Form a pre-list of columns, what's the problem?

     $columns = [ // all columns from GridView::widget execution without colors ]; if ($colorDatas) { $columns[] = ['filter' => Select2::widget /* all code for column */] } GridView::widget([ // your settings 'columns' => $columns ]);