Yii2 Gridview display all columns

Viewed 132

How can I display all columns in gridview without define the columns that I want to displau in view ?

In Yii2 doc,

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [ //define columns here
        'id',
        'name',
        'created_at:datetime',
        // ...
    ],
]) ?>

Can we just

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => '*',
]) ?>
1 Answers

I don't think there is such a wildcard, but you can use attributes() method on your model (if you have an instance) or array_keys(Model::getTableSchema()->columns);

Related