Question

I have been searching through the internet for an answer to my question but I haven't found one. My problem is that I have column in my CGridView that contains a blob. My blob is a comment that is written by some users and can be edited. The comment can have a single sentence or can contain many paragraphs. In that case, I want to be sure that in my CGridView the separation between the paragraphs are visible.

For now, my CGridView is displaying the comment but doesn't respect the lineskips. How do I do that?

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'grid-demande',
'dataProvider'=>$dataProviderDemande,
'emptyText'=>'No data',
'cssFile'=>Yii::app()->request->baseUrl."/css/my_gridview.css",
'columns'=>array
(
    array(            
        'name'=>'ch_comment',
        'type'=>'raw',
        'htmlOptions'=>array('width'=>'21%'),
    ),
);
Was it helpful?

Solution 2

Try the following for your column definition in the gridview:

array(            
    'name'=>'ch_comment',
    'value'=>'nl2br($data->ch_comment)',
    'type'=>'raw',
    'htmlOptions'=>array('width'=>'21%'),
),

This will convert line breaks to <br /> tags, which should solve your issue.

OTHER TIPS

You can use the formatter 'ntext': http://www.yiiframework.com/doc/api/1.1/CFormatter#formatNtext-detail

In this case, in the 'columns' array just add:

'ch_comment:ntext',
//short forme
array(
  'name' => 'ch_comment',
  'type' => 'ntext'),
//long forme

you can try changing type=>'raw' to type=>'html'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top