Running total in CGridView For CSqlDataProvider

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.

Any help would be appreciated.

Thank you.

[color="#008000"]NOTE: moved to proper section (General Discussion for Yii 1.1.x instead of Tips, Snippets and Tutorials)[/color]

Sorry about that @mdomba. Can anyone please help me out here?

How is your CGridView getting the data - should be from a dataprovider… is it working the sorting/filtering?

If all this works than please explain what is the problem of calculating the SUM() of your data for the specified column…

@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.

Any help would be appreciated.

Below is my view





$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',

),

));