A
A
Artyom2015-06-21 12:16:55
Yii
Artyom, 2015-06-21 12:16:55

Yii2: How to add one column in GridView under certain condition?

Hello. Tell me how to add one column under a certain condition?
So not an option: After all, if empty, then it gives an error.
(1 == 1) ? 'test' : '',

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Belikov, 2015-06-22
@DeOne

For example, you can put all the columns in a variable and, depending on the condition, add or remove.

$columns = [
  // coulumns
];
if($condition) {
  $columns[] = $someColumn;
}
GridView::widget([
  'columns' => $columns,
  // ...
]);

S
sokollondon, 2018-02-14
@sokollondon

Each column has a parameter visible. If it falseis , then the column is not displayed. For example:

GridView::widget([
    'columns' => [
        [
            'attribute'=>'column_name',
            'visible'=> boolval($condition)
        ],
        // ...
    ]
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question