2017-01-10 27 views
2

我有这样的代码,并且我想在'comment'部分中包装文本。在小部件中包装文本 - Yii2

<?= GridView::widget([ 
     'dataProvider' => $dataProvider, 
     'filterModel' => $searchModel, 
     'columns' => [ 
      ['class' => 'yii\grid\SerialColumn'], 

      'id', 
      'place_id', 
      'place_rating', 
      'comment:ntext', 
      'hire_price', 
      'additional_cost', 
      'presentation_id', 

      ['class' => 'yii\grid\ActionColumn'], 
     ], 
    ]); ?> 

我发现建议,我应该把'style' => 'text-wrap'地方,但不知道在哪里,我尝试了一些地方,但没有很好的效果。

+0

请告诉我们什么你已经尝试过了。 – Rabban

+0

在倒数第二行:'$ tableOptions = ['class'=>'table table-striped table-bordered text-wrap'],' – Olga

回答

0

在GridView中添加contentOptions

<?= GridView::widget([ 
    'dataProvider' => $dataProvider, 
    'filterModel' => $searchModel, 
    'tableOptions' => ['class' => 'table table-striped table-bordered'], 
    'columns' => [ 
     ['class' => 'yii\grid\SerialColumn'], 

     'id', 
     'place_id', 
     'place_rating', 
     [ 
      'attribute' => 'comment', 
      'contentOptions' => ['class' => 'text-wrap'], 
     ], 
     'hire_price', 
     'additional_cost', 
     'presentation_id', 

     ['class' => 'yii\grid\ActionColumn'], 
    ], 
]); ?> 
+0

它没有改变任何东西:( – Olga

+0

显示更新的答案....并尝试 – vishuB

0

创建样式表一个新的CSS规则,并直接添加一个类text-wrap或做如下

方法1:

'contentOptions' => ['style' => ['max-width' => '100px;', 'height' => '100px']] 

更新

[ 
    'label' => 'Comment', 
    'attribute' => 'comment', 
    'format'=>'ntext', 
    'contentOptions' => ['style' => ['max-width' => '100px;', 'height' => '100px']] 
], 

或里面添加CSS类,并就以下

方法2:

'contentOptions' => ['class' => 'text-wrap']  

添加下面的CSS代码在你的CSS文件

.text-wrap{ 
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ 
white-space: -pre-wrap;  /* Opera 4-6 */ 
white-space: -o-pre-wrap; /* Opera 7 */ 
white-space: pre-wrap;  /* css-3 */ 
word-wrap: break-word;  /* Internet Explorer 5.5+ */ 
white-space: -webkit-pre-wrap; /* Newer versions of Chrome/Safari*/ 
word-break: break-all; 
white-space: normal; 
} 
+0

但正如'vishub'所提到的,''contentOptions'=> ['style'=> ['max-width'=>'100px;','height'=>'100px']]'' – Olga

+0

'你需要添加它在属性选项 –

+0

好吧,但我试过,并没有注意到任何差异 – Olga