0

Currently my CGridView gives following result.

http://imageshack.us/a/img821/2391/44264318.png

Here City is actually CityID From a parent table. City table has one-to-many relationship with Campus table. I want to show city.cityname instead of city.cityid from parent table. Can someone help please. Database structure is as

http://imageshack.us/photo/my-images/845/82338990.png/

ali asad
  • 1,329
  • 4
  • 17
  • 23

2 Answers2

0

change that column to

array (
'name'=>'mycol
'value'=>'$data->city->cityname',
);

where city is a relation name, and cityname is an attribute from the linked class.

To sort see this article http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/

Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • Thanks it is showing values with this code widget('zii.widgets.grid.CGridView', array( 'id'=>'campus-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'CampusName', array( 'name'=>'CityID', 'value'=>'$data->city->CityName', ), 'Description', array( 'class'=>'CButtonColumn', ), ), )); ?> But it is not searching records based on CityName. Is is searching records based on CityID. – ali asad Oct 15 '12 at 02:57
  • Thanks above article helped me. – ali asad Oct 15 '12 at 14:34
0

in your grid columns use:

array (
   ...
   'city.cityname',
   ... other columns...
);
Asgaroth
  • 4,274
  • 3
  • 20
  • 36