Sorting in Grid View


I have a grid where two columns: participantTotal and are defined in relations method:

public function relations()

{ return array( …

‘participantTotal’=>array(self::STAT, ‘Participant’,‘ParticipantServices(ServiceId, ParticipantId)’),

‘ServiceType’ => array(self::BELONGS_TO, ‘Service’, ‘UAHLServiceTypeId’),



<?php $this->widget(‘zii.widgets.grid.CGridView’, array(




	array('name'=&gt;'type', 'header'=&gt;'Service Type', 'value'=&gt;'&#036;data-&gt;ServiceType-&gt;name'),



	array('name'=&gt;'NumberOfGuests', 'value'=&gt;'&#036;data-&gt;NumberOfGuests'),





)); ?>

How should I define $sort to sort these two columns?

Thank you very much in advance. Respond time on this forum is phenomenal!



you need reassign CDataProvider::sort as a new CSort.

I know that. Problem is HOW, as when I tried this:

$sort=new CSort;


‘type’ => array( “asc”=>‘’, “desc” => ‘ desc,’ ),

‘participantTotal’ => array( “asc”=>‘participantTotal’, “desc” => ‘participantTotal,’ ),


I had errors as query

SELECT * FROM Service t WHERE UserId=:ycp0 ORDER BY LIMIT 10

is not aware of the STAT and related other table

check out the 7th codeblock for an example:

Thank you for your post! and the time you saved me…