3
votes

Has anyone been able to set up word-wrapping for a Yii GridView DataColumn?

Here is how I have set up the column:

 [
    'class' => 'kartik\grid\DataColumn',
    'attribute'=>'description',
    'format'=>'html',   
    'contentOptions' => [
        'style'=>'max-width:150px; min-height:100px; overflow: auto; word-wrap: break-word;'
    ],
],

And no matter what settings I use I can't get the text to wrap. I was hoping to have it wrap causing the row height to dynamically grow but it is not doing that. Here is what the column looks like: enter image description here

Anyone have any ideas how to make this work?

Thanks!

2

2 Answers

4
votes

you need override white-space: nowrap; from site.css

[
    'class' => 'kartik\grid\DataColumn',
    'attribute'=>'description',
    'format'=>'html',   
    'contentOptions' => [
        'style'=>'max-width:150px; overflow: auto; white-space: normal; word-wrap: break-word;'
    ],
],
3
votes
Try using options

 'options' => [
    'style'=>'max-width:150px; min-height:100px; overflow: auto; word-wrap: break-word;'
],

otherwise try using form raw an in value return the html and style you need

[
 'class' => 'kartik\grid\DataColumn',
  'attribute'=>'',
  'format'=>'raw',   
  'value' => function($model) {
     return 'span  'style'='max-width:150px; min-height:100px; 
               overflow: auto; word-wrap: break-word;' . $model->description  
            .  </span> 
      },
   ],
],