Reputation: 21
I have a gridview for a dataProvider that i create in view from an JSON response from an API and i want to show some columns and not all from the data structure that i'm getting, so i have a fields array and want to create columns by the array.
I create an array like this
$array=['column1','column2','column3'];
and when i use in columns parameter gives me an error
I tried like a string too but not success. like this
$array="'column1','column2','column3'";
echo GridView::widget([
'id' => 'prec_inc_grid',
'columns' => [
$array,
],]);
may show the well formed grid view but gives me this error
Setting unknown property: yii\grid\DataColumn::0
I suppose that is because the array is something like this
Array ( [0] => column1 [1] => column2 [2] => column3)
Upvotes: 1
Views: 427
Reputation: 21
I figured out how to, because the JSON decode process was right, it was the [ ] after the " 'columns'=>" i deleted it and was 'columns'=>$array, and run perfect. Thanks.
Upvotes: 1