Yii Framework Forum: CGridView add sortable column - Yii Framework Forum

Jump to content

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

CGridView add sortable column I can add a column but not sort. Rate Topic: -----

#1 User is offline   MattCNS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 20-February 10

Posted 11 April 2010 - 07:04 PM

Hi,

I have two columns in my datagrid that I'm adding together and displaying in a third column. I can do this but the datagrid won't let me sort the calculated column. Here's my code:

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		'risk_id',
		'description',
		/*'objective',*/
		'likelihood',
		'rank',
         array(
                'header'=>'Score',
                'value'=>'$data->rank + $data->likelihood',
                'name'=>'$data->rank + $data->likelihood',
                'sortable'=>true,
                ),


I'm sure that I'm doing something wrong with the 'Name' property of the DataColumn but I can't work out where the problem is.
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 12 April 2010 - 07:31 AM

CSort handles those sorting options, CSort checks if the name is in the attribute list of the AR object (meaning the name exists as a column in the underlying table), If it is it will allow sorting otherwise it won't. The only option for you is to add an attribute entitled 'score' that will be used as the result of the code ($data->rank + $data->likelihood) you have above. You will need to override several methods in the AR object to include that attribute dynamically.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
1

#3 User is offline   MattCNS 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 20-February 10

Posted 12 April 2010 - 07:48 AM

Thanks Vince. I was wondering if that was the case. It might be easier to just store the score in the DB.
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