I am new to Yii2 Framework and I tend to end up in situations that i don’t get answers to… To blab about my current situation, I have a table with user_id , score and date column. I want to display a GridView report by pivoting the data with date between a given week as header, (unique) user in first column and score as the data corresponding to each user against the date. I wrote a query ActiveDataProvider query which does that and sends them to view.
The main challenge for me is to set up column in GridView Widget where the dates (7 day dates of given week) can be made header.
Is there any method for this I missed ?? some pointers would be appreciated immensely
Thanks @uldisn for your response however to clarify further, I can get data as array but my challange is to input data into the column as I don’t have fixed column label/header…
Thanks man… I did took some reference from your code and it helped me. I can atleast populate the table as desired, however since I am getting the data as array rather than model object, how can i reference the relation of each data to the model in GridVIew value function ?
Since I have the start date and end date:
$period = new DatePeriod($start, $interval, $p_end);
foreach ($period as $pd)
{
$columns[] = [
'header' => date('d/m/Y', strtotime($pd->format('Y-m-d'))),
'attribute' => $pd->format('Y-m-d'),
'value' => function($model) use ($pd) {
/ /How to convert my array data to model here?
},
];
}