2

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
  • its not just the data column that it has to render but it can be a SerialColumn or ActionColumn e.t.c too so just * wont help also the method that initializes these columns initColumns() is declared as protected so you cant override it too to add your own implementation for it. so just either dont specify columns option and let the guessColumn() do the work Commented Aug 19, 2020 at 23:27

1 Answer 1

1

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);

Sign up to request clarification or add additional context in comments.

1 Comment

‘Columns’ => [], Is all you need (or simple remove the columns row altogether. So long a NOTHING is passed for the columns parameter, then all columns will be displayed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.