CGridView - concatenate column values

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,

		),

	),

));



it works well with CDetailView, but not with CGridView

What happens in Cgridview as opposed to detailview?

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




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



this way worked for me, thanks!

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

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);












array(

			'header'=>'Name',

			'name'=>'first_name',

			'value'=>'$data->first_name." ".$data->last_name'


		),