Sorting in Grid View

Hi,

I have a grid where two columns: participantTotal and ServiceType.name 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’),

)}

grid:

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

'id'=&gt;'service-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'columns'=&gt;array(


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


	'ServiceDate',


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


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


	array(


		'class'=&gt;'CButtonColumn',


	),


),

)); ?>

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

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

Regards,

Jerzy

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

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

$sort=new CSort;

$sort->attributes=array(

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

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

);

I had errors as query

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

is not aware of the STAT and related other table

check out the 7th codeblock for an example: http://www.mrsoundless.com/post/2011/05/09/Searching-and-sorting-a-column-from-a-related-table-in-a-CGridView.aspx

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