Customize GridView with ArrayDataProvider column names

Hi everybody!

I’m developing an integration between Google Drive (spreadsheet in this case) and my webapp. Integration works like this:

In my Model afterFind() method i populate the attribute $_prices with an ArrayDataProvider filled with remote spreadsheet content like this (Google Drive fileId is stored in $model->pricelist_id):



            $file = $service->files->export($this->pricelist_id, 'text/csv', array('alt' => 'media'));


            $data = str_getcsv($file, "\n"); //parse the rows 

            foreach ($data as &$row) {

                $row = str_getcsv($row, ","); //parse the items in rows

                $rows[] = $row;


            $columnsRow = array_shift($rows);

            $models = [];

            foreach ($rows as $row) {

                $model = [];

                foreach ($columnsRow as $k => $column) {

                    $model[$column] = $row[$k];


                $models[] = $model;


            $this->_prices = new ArrayDataProvider([

                'allModels' => $models



where $models is the array representation of the csv file obtained via Google Drive API.

In the view I simply render a GridView with the prices:



            <?= GridView::widget([

                'dataProvider' => $model->prices

            ]); ?>


where $model is passed by the controller.

Everything is working fine. My problem is in the labels of the GridView columns. In my original Google Sheet I have column names like:

15.03 - 04.06

but in GridView they render like

15 03 04 06

due the yii\base\Model generateAttributeLabel() method which replace underscores, dashes and dots with blanks.

So, how can I preserve the original column names? Every Google Sheet have many columns with different names in this format so I need a “dynamic solution” :)

Thank you