dhenet5254
(Redhen 07)
September 11, 2013, 8:00am
1
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
konapaz
(Konapaz)
September 11, 2013, 8:43am
2
Hi
check this
array(
'header'=>'a title'
'value'=>'yourController:aStaticMethodThatReturnsWhatYouWant($data)', //$data is the record foreach row
}
dhenet5254
(Redhen 07)
September 11, 2013, 8:56am
3
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…
konapaz
(Konapaz)
September 11, 2013, 9:51am
4
you could use SQL Statements
$average = Yii::app()->db->createCommand('select AVG(column) FROM your_table')->queryScalar();
dhenet5254
(Redhen 07)
September 12, 2013, 8:51am
5
thank you got it sir… but how can i sort and filter the ‘header’?thnx
konapaz
(Konapaz)
September 12, 2013, 1:08pm
6
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.
Create an function that initializes all records for this attribute according to getInterpretation algorithm
Add the appropriate condition in search method of your model for this model
dhenet5254
(Redhen 07)
September 12, 2013, 11:52pm
7
got it. thank you so much…