Yii Framework Forum: CGridView - concatenate column values - Yii Framework Forum

Jump to content

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

CGridView - concatenate column values Rate Topic: ***** 1 Votes

#1 User is offline   betelgeuse 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 12-January 09

Posted 11 July 2010 - 04:29 PM

I´m trying to concatenate column values without success:

<?php $this->widget('zii.widgets.grid.CGridView', array(
...
	'columns'=>array(
...
		array(
			'header'=>'balblal',
                        'value'=>$model->a.' '.$model->b.' '.$model->b,
		),
	),
));


is it possible? what am i doing wrong?
a code snippet says more than a thousand words
0

#2 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 11 July 2010 - 04:32 PM

View PostFlavio, on 11 July 2010 - 04:29 PM, said:

I´m trying to concatenate column values without success:

<?php $this->widget('zii.widgets.grid.CGridView', array(
...
	'columns'=>array(
...
		array(
			'header'=>'balblal',
                        'value'=>$model->a.' '.$model->b.' '.$model->b,
		),
	),
));


is it possible? what am i doing wrong?


Not sure if it would run into errors with processing through the array but a simple fix is to make a new variable at the top of the widget (before you invoke it):

$newVar = $model->a.$model->b and so on and then use

<?php $this->widget('zii.widgets.grid.CGridView', array(
...
	'columns'=>array(
...
		array(
			'header'=>'balblal',
                        'value'=>$newVar,
		),
	),
));

0

#3 User is offline   betelgeuse 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 12-January 09

Posted 11 July 2010 - 04:48 PM

View Postwhoopass, on 11 July 2010 - 04:32 PM, said:

Not sure if it would run into errors with processing through the array but a simple fix is to make a new variable at the top of the widget (before you invoke it):

$newVar = $model->a.$model->b and so on and then use

<?php $this->widget('zii.widgets.grid.CGridView', array(
...
	'columns'=>array(
...
		array(
			'header'=>'balblal',
                        'value'=>$newVar,
		),
	),
));



it works well with CDetailView, but not with CGridView
a code snippet says more than a thousand words
0

#4 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 11 July 2010 - 05:03 PM

View PostFlavio, on 11 July 2010 - 04:48 PM, said:

it works well with CDetailView, but not with CGridView


What happens in Cgridview as opposed to detailview?
0

#5 User is offline   betelgeuse 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 12-January 09

Posted 11 July 2010 - 05:13 PM

View Postwhoopass, on 11 July 2010 - 05:03 PM, said:

What happens in Cgridview as opposed to detailview?


display no errors.. and a blank column
a code snippet says more than a thousand words
0

#6 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 11 July 2010 - 05:41 PM

View PostFlavio, on 11 July 2010 - 05:13 PM, said:

display no errors.. and a blank column


Tip:
Use $data->a, $data->b and enclose the complete expression in quotes ("deferred" evaluation when columns are rendered).

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#7 User is offline   betelgeuse 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 12-January 09

Posted 11 July 2010 - 06:06 PM

'value'=>'$data->a.\' \'.$data->b.\' \'.$data->c',


this way worked for me, thanks!
a code snippet says more than a thousand words
2

#8 User is offline   btilley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 21-February 12

Posted 20 June 2012 - 12:49 PM

Question: How would you make this column searchable and sortable in CGridView?
0

#9 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 488
  • Joined: 08-October 12
  • Location:Austria

Posted 16 November 2012 - 08:47 AM

Hi btilley,

You can make this column searchable and sortable by modifying the model class search() method


$data->a.\' \'.$data->b.\' \'.$data->c

$criteria->compare('CONCAT(a,b,c)',$this->a);

Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

#10 User is offline   Nisanth thulasi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 10-July 12
  • Location:Kochi

Posted 22 March 2013 - 04:56 AM





array(
			'header'=>'Name',
			'name'=>'first_name',
			'value'=>'$data->first_name." ".$data->last_name'

		),



Thanks
Nisanth Thulasi
1

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