我有这样的代码,我想将文字换成'评论'一部分。
<?= 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 :(得分: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'],
],
]); ?>
答案 1 :(得分: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;
}