Yii2 Kartik GridView Word-Wrapping

时间:2016-08-21 02:09:47

标签: gridview yii yii2

有没有人能够为Yii GridView DataColumn设置自动换行?

以下是我设置列的方法:

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

无论我使用什么设置,我都无法将文字包裹起来。我希望让它包裹导致行高度动态增长,但它没有这样做。这是列的样子: enter image description here

任何人都有任何想法如何使这项工作?

谢谢!

2 个答案:

答案 0 :(得分:3)

Try using options

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

否则尝试使用表单raw a in value返回你需要的html和样式

[
 '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> 
      },
   ],
],

答案 1 :(得分:2)

你需要覆盖空格:nowrap;来自site.css

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