Sorting In Yii

Hi, I am trying to implement sorting with Yii list view. I have joined 2 tables named provider_favourite and service_request in list view. And the fields and contents from both tables are listing in the list view. But sorting is working only in provider_favourite table, not from service_request table.How can I sort the fields from service_request table? Iam using csort for sorting. I also tried CGrid view. But the same problem is happening in grid view also …

Iam using the following code to join

     $criteria = new CDbCriteria;

        $criteria->select = 'favourite_notes,favourite, favourite_added_date,max_budget,preferred_location';

        $criteria->join = 'LEFT JOIN service_request AS s ON  service_request_id = favourite';

        $criteria->condition = 'favourite_type = 1';

        $sort=new CSort('ProviderFavourite');

        $sort->defaultOrder='favourite_notes ASC,favourite_added_date asc,max_budget asc';


            $type = 2;

        $data = new CActiveDataProvider('ProviderFavourite', array('criteria' => $criteria, 'pagination' => array('pageSize' => 4)


        $this->renderPartial('favourites', array(

            'ModelInstance' => ProviderFavourite::model()->findAll($criteria),

            'dataProvider' => $data, 'type' => $type, 'sort'=>$sort,


If more details needed, I will provide. Thanks in advance

try this

$sort->attributes = array(

        	'field_name1' => 'relation_name.field_name1',



where field_name1 is from other table

and field_name2 is from same table

pass $sort like this in dataProvider

$data = new CActiveDataProvider('ProviderFavourite', array(

    'criteria'  => $criteria,

	'pagination' => array('pageSize' => 4),



[size=2]Thanks, now a sort link is showing in the view, on clicking the page is also getting reloaded, but sorting is not done. I am using the following code to echo it[/size]

<?php echo $sort->link('max_budget'); ?> 

is there any more changes required

u passed sort attributes to ListView like this

$this->widget('LlistView', array(

	'dataProvider' => $model,

	'sortableAttributes' => array(





Yes, I had provided so…

  $this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider,'itemView'=>'index_1',     


'template' => '  {items}{pager}',



but the same problem is showing

edit $sort like this

$sort->attributes = array(


   	'asc'=>'relation_name.field_name ASC' ,

   	'desc'=>'relation_name.field_name DESC',




for more about sort listview try below link

Thanks, it is not working, let me check the link you provided