# Yii Framework Forum: CGridView sorting - Yii Framework Forum

Page 1 of 1

## CGridView sorting Rate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.yiiframework.com/forum/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=8293&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1bitmatix

• Standard Member
• Group: Members
• Posts: 162
• Joined: 23-March 09

Posted 30 March 2010 - 02:15 AM

In a GridView I have a column displaying values of a related model like:

`objRelated.strName:text:Name`

and I want to know how I can sort by this column? The column header isn't a link Seems like only properties of the main model itself get a link in column header.
0

### #2vamp

• Standard Member
• Group: Members
• Posts: 181
• Joined: 30-January 09

Posted 30 March 2010 - 02:41 AM

bitmatix, on 30 March 2010 - 02:15 AM, said:

In a GridView I have a column displaying values of a related model like:

`objRelated.strName:text:Name`

and I want to know how I can sort by this column? The column header isn't a link Seems like only properties of the main model itself get a link in column header.

try to define (for CActiveDataProvider)
```'sort'=>array('attributes' => array(
'myColumnName' => array(
'label'=>'NAME',
'asc'=>\$expr='CUSTOM_SQL_EXPRESSION_TO_APPLYING',
'desc'=>\$expr.' DESC',
),
...);

```

then:
``` \$columns=array(
array(
'name'=>'myColumnName',
'value'=>'CHtml::value(\$data,"my.related.property.name")',
),
...```

--
Thanks, you make me stronger!
0

### #3bitmatix

• Standard Member
• Group: Members
• Posts: 162
• Joined: 23-March 09

Posted 06 May 2010 - 08:49 AM

vamp, on 30 March 2010 - 02:41 AM, said:

try to define (for CActiveDataProvider)
```'sort'=>array('attributes' => array(
'myColumnName' => array(
'label'=>'NAME',
'asc'=>\$expr='CUSTOM_SQL_EXPRESSION_TO_APPLYING',
'desc'=>\$expr.' DESC',
),
...);

```

then:
``` \$columns=array(
array(
'name'=>'myColumnName',
'value'=>'CHtml::value(\$data,"my.related.property.name")',
),
...```

thanks for your reply. I've tried to use your suggested code, but I got an error. What does "\$expr" stands for?
1

### #4Jaz Manister

• Standard Member
• Group: Members
• Posts: 109
• Joined: 27-October 09
• Location:Rural Western New York, USA

Posted 06 May 2010 - 08:53 AM

I accomplished this slightly differently. See the post where I detailed it.
0