When use CGridView to display Active Records with relationship, we should notice some points
-
For CGridView’s Columns properties, you should use ‘relation[property]’ as your columns name (e.g. user[nick]). Or this column name will be fillet by CDataColumn::renderFilterCellContent() defined in Yii/zii/widgets/grid/CDataColumn.phps . (refer code
strpos($this->name,'.')==false
conditions normally in line 94). -
use
$data->relation->property
as CGridView’s Column’s value property. such asvalue=>'$data->user->nick'
-
Create your search condition into Model’s search method by visit $_GET variable.
-
Add $_GET to attributes in you Controller’s list method, so the filter header could remember the last typed value.
-
Of course , just add
with=>array('relation')
andtogether=true
property into your the CDbCriteria instance used in Model’s search method