Yii Framework Forum: CGridView sorting - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView sorting Rate Topic: -----

#1 User is offline   bitmatix 

  • Standard Member
  • PipPip
  • Yii
  • 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

#2 User is offline   vamp 

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

Posted 30 March 2010 - 02:41 AM

View Postbitmatix, 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")',
   ),
   ...

-Posted Image-
Thanks, you make me stronger!
0

#3 User is offline   bitmatix 

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

Posted 06 May 2010 - 08:49 AM

View Postvamp, 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

#4 User is offline   Jaz Manister 

  • Standard Member
  • PipPip
  • Yii
  • 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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users