Reputation: 443
I have code like that, and I would like to wrap text in 'comment' part.
<?= 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'],
],
]); ?>
I found advice, that I should put 'style' => 'text-wrap'
somewhere, but have no idea where, I tried some places, but with no good effect.
Upvotes: 2
Views: 1376
Reputation: 1092
Create a new css rule in your stylesheet and add a class text-wrap
or do it directly as follows
method 1:
'contentOptions' => ['style' => ['max-width' => '100px;', 'height' => '100px']]
Update
[
'label' => 'Comment',
'attribute' => 'comment',
'format'=>'ntext',
'contentOptions' => ['style' => ['max-width' => '100px;', 'height' => '100px']]
],
or add class inside css and do following
method 2:
'contentOptions' => ['class' => 'text-wrap']
Add below css code in your css file
.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;
}
Upvotes: 1
Reputation: 4261
Add contentOptions
in GridView
<?= 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'],
],
]); ?>
Upvotes: 0