I have this need to create custom report that has aggregation and grouping etc. I have successfully created the CGridView for that particular report. Now I need to add a footer row(s) for total & average for two of the columns.
How can I do that? Most of the solutions that I looked at are talking about the $model but in my case, I am not using any model class. I have created a module for reports that doesn’t tie back to any particular model.
@mdomba, I am actually using CSqlDataProvider for my data. Sorting etc works fine. I just need two footer rows that gives me average of the column and a total of the column.
$sql="select floor(rand() * 1000) as id, a.facilityName, b.Rate, a.Days, (b.Rate * a.Days) as total from ";
$sql .= "(select f.facility_name as facilityName, sum(m.billing_hours) as Days from medicalrates m, facility f ";
$sql .= "where f.id = m.facility_id and m.month='". $month . "' group by f.facility_name) as a, ";
$sql .= "(select f1.facility_name as facilityName, avg(r.rates) as Rate from rates r, rateyear ry, facility f1 ";
$sql .= "where ry.id = r.year_id and f1.id = r.facility_id group by f1.facility_name) as b ";
$sql .= "where a.facilityName = b.facilityName";
$dataProvider = new CSqlDataProvider($sql, array(
'sort'=>array(
'attributes'=>array(
'facilityName', 'Days', 'Rate','total',
),
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'facilityName',
'Days',
array(
'name'=>'Rate',
'type'=>'raw',
'value'=>'$data["Rate"]',
),
'total',
),
));