December 02 2015

Yii2 gridview column pass an array as param

Tagged Under :

Yii
In Yii2 now you are allow pass an array as param to gridview column for display the data. Below is the example how to pass array to gridview column.

Exmaple:
The $status is an array and $data is the model results.
'content' => function($data) use ($status) {
  return (isset($status[$data->status]) ? $status[$data->status] : $data->status);
},

Complete Example:
 $model->search(),
  'filterModel' => $model,
  'showOnEmpty'=>true,
  'columns' => [
    'id',
    'name',
    [
      'attribute' => 'status',
      'filter' => $status,
      'content' => function($data) use ($status) {
        return (isset($status[$data->status]) ? $status[$data->status] : $data->status);
      },
    ],
  ],
]); ?>

Make a Comment

*

code