1

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)
1
  • how are you creating the array to feed the GridView ? also show the response you are getting from the API Commented May 20, 2019 at 21:05

1 Answer 1

1

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.

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

Comments

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.