Labels In Cgridview

I’m using a CGridView widget in my view file

where some of the columns are showing data from related tables

e.g.




$this->widget('zii.widgets.grid.CGridView', array(

	    'dataProvider'=>$data_reqs,

	    'columns'=>array(

			array('name' => 'Field1', 'value' => '$data->Field1'),

			array('name' => 'xxxx', 'value' => '$data->requestREL->RelatedField'),

 			    ),

	));



where Field1 is from current model ,

RelatedField is a field defined in the related model,

and requestREL is the name of the relationship defined in the current model.

The problem is with the labeling.

While Field1 gets its appropriated name from function:attributeLabels,defined inside

his model , I can’t find a way to print a label for the related table field( e.g. RelatedField).

I tried to make a new entry in function:attributeLabels , with the desired label , but then,

in the Grid, the label isn’t a hyperlink with sorting mechanism etc. like the default fields

(not to mention that its font color is white and I have to change it via CSS to show up)

Any ideas ?

you can add headers explicitly in grid definition:




$this->widget('zii.widgets.grid.CGridView', array(

            'dataProvider'=>$data_reqs,

            'columns'=>array(

                        array('name' => 'Field1', 'value' => '$data->Field1', 'header'=>'my header'),

                        array('name' => 'xxxx', 'value' => '$data->requestREL->RelatedField', 'header'=>'my header'),

                            ),

        ));



Wow!

Thanks a lot about the tip , didn’t know that.

But it stil shows up with font color in white and without any functionality.

:(

read this: http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/

Also this may helps you

http://www.yiiframework.com/doc/api/1.1/CBaseListView#htmlOptions-detail

http://www.yiiframework.com/doc/api/1.1/CGridView#rowCssClass-detail

Thanx a lot guys for the replies and sorry for the delay.