How To Get Sum, Average And Interpretation In Cgridview

i have a question question on how to compute sum, average and interpretation in cgridview

example i have a table called rating w/ columns

  id | rating1 | rating2 | rating3 |rating4

ex. 1 98 99 0 98

interpretation: >= 96(outstanding), >= 91(superior), >=86(very satisfactory)

on my cgrid view i want to show like this:

id | total rating | average | intepretation

1 | 295 | 98.3 | outstanding


check this


'header'=>'a title'

'value'=>'yourController:aStaticMethodThatReturnsWhatYouWant($data)', //$data is the record foreach row


than you sir konapaz, i know how to get the view on cgridview the problem is how to get that result i mean how to compute… or any example or reference,link…

you could use SQL Statements

$average = Yii::app()->db->createCommand('select AVG(column) FROM your_table')->queryScalar();

thank you got it sir… but how can i sort and filter the ‘header’?thnx

Hi raiethan

sorting on cgridview works by name of attribute (value of name) not for custom value

You could create an extra attribute (column in table) in model.

  1. Create an function that initializes all records for this attribute according to getInterpretation algorithm

  2. Add the appropriate condition in search method of your model for this model

got it. thank you so much…