$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		array(
			'name' => 'id',
			'type'=>'raw',
			'value' => 'CHtml::link(CHtml::encode($data->id),array("example/view","id"=>$data->id))',
		),
		array(
			'name' => 'customusername',
			'type'=>'raw',
			'value' => 'CHtml::link(CHtml::encode($data->userid->username),array("user/admin/view","id"=>$data->userid->id))',
		),
		array(
			'name'=>'customemail',
			'type'=>'raw',
			'value'=>'CHtml::link(CHtml::encode($data->userid->email), "mailto:".$data->userid->email)',
		),
If is use username this write from the model attribute, but is use custom name this is the header name and i dont use the sort options. How to use custom name with sort options?
         
        
           
         
            
       
      
        
          
          
            zilles  
          
              
                May 2, 2012,  9:26pm
               
              2 
           
         
        
          I’m not absolutely sure that I understand your question, but I think you might be looking for the “header” key:
                array(
                        'header' => 'customusername',
                        'name' => 'userid.username',
                        'type'=>'raw',
                        'value' => 'CHtml::link(CHtml::encode($data->userid->username),array("user/admin/view","id"=>$data->userid->id))',
                ),
Also, I believe there is already an "email" type that will do the formatting you want for your email attribute:
"userid.email:email:customemail"
         
        
           
         
            
       
      
        
        
          
I’m not absolutely sure that I understand your question, but I think you might be looking for the “header” key:
                array(
                        'header' => 'customusername',
                        'name' => 'userid.username',
                        'type'=>'raw',
                        'value' => 'CHtml::link(CHtml::encode($data->userid->username),array("user/admin/view","id"=>$data->userid->id))',
                ),
Also, I believe there is already an "email" type that will do the formatting you want for your email attribute:
"userid.email:email:customemail"
 
 
It’s great.
If is use foreign table, how to sortable?
                array(
                        'header' => 'customusername',
                        'name' => 'userid.username', //is it the foreign table column and not sortable
                        'type'=>'raw',
                        'value' => 'CHtml::link(CHtml::encode($data->userid->username),array("user/admin/view","id"=>$data->userid->id))',
                ),
I find the solution. link
         
        
           
         
            
       
      
        
        
          
This is, if I may say, a classic wiki:
Searching and sorting by related model in CGridView
         
        
           
         
            
       
      
        
        
          Hi
for foreign table
you have to use
if foreign table BELOGNS_TO
$data->foreignTableName->FieldName;
if foreign table HAS_MANY
$data->foreignTableName[0]->FieldName;
Thanks