This is Seeni from chennai.
As our friend Softark
suggested whatever the logic you have done to customize a field in CGrid,
You have to apply that logic at database level in the form of sql.
I tried to simulate your scenario.
Your requirements and demands may be complex.I may not be able to meet them.
Any way I hope this will help you.
I have two tables.
One user belongs to a group through g_id.
Every worker is given some tasks(assigned
How many of tasks they have completetd is known from completed
Now we want to know the overall efficiency of a group.Of all the tasks assigned for a particular group,
we need to know ,how many have been completed.We want to dispaly it as efficiency
in Group CGrid.
class Group extends CActiveRecord
public $efficiency; //declared a virtual property efficiency.
public function rules()
array('name', 'length', 'max'=>64),
array('id, name,efficiency', 'safe', 'on'=>'search'),//Made that property safe in search.
public function search()
$sql="SUM(worker.completed)/SUM(worker.assigned)*100 "; //leave a space before the end of quotes.
* We are using join directly .No need to bother about "with" or "together".
* We are grouping by group.id. So calculation done in $sql is applied within the group only.
* There is regExp check for user input. which is going to accept integer or float with prefixed operator signs.
$criteria->join="LEFT JOIN worker ON worker.g_id=t.id";
return new CActiveDataProvider($this, array(
<?php $this->widget('zii.widgets.grid.CGridView', array(
I may be doing very simple thing. Situation in your hand may be complex.
Any way we can customize the situation playing with sql and also passing parameters to search function.