php - Yii2:如何在 Gridview 的所有行上显示更少的行?
解决方案
根据指定的行数显示文本。
假设 DB 中的文本
已保存。太\n
你根据必要的分隔符来做...... <br>
或<p>
......
// Attribute name: text
[
'attribute' => 'text',
'format' => 'html',
'value' => function ($model) {
$array= array_chunk(explode('<br>', nl2br($model->text)),4);
return implode("<br>",$array[0]);
},
],
根据指定字符数显示文本
[
'attribute' => 'text',
'value' => function ($model) {
// without breaking the word
return mb_substr($model->text,0,strpos($model->text, ' ', 400));
// by breaking the word
return mb_substr($model->text, 0, 400, mb_detect_encoding($model->text))." ...";
},
],
根据元素宽度显示文本。最大宽度
[
'contentOptions' => ['style' => 'text-overflow: ellipsis; white-space: nowrap; max-width: 25vw; overflow: hidden;'],
'attribute' => 'text',
'value' => function ($model) {
return $model->text;
},
],
根据高度显示文本
注意:根据您的字体和要求更改高度。
[
'format' => 'raw',
'attribute' => 'text',
'value' => function ($model) {
return '<div style="line-height: 1.2em; height: 4.8em; overflow: hidden;">'.\yii\helpers\HtmlPurifier::process($model->text).'</div>';
},
],
推荐阅读
- reactjs - 使用 RequireJS 将 React16 Build 加载到另一个应用程序中
- python-3.x - 无法使用 python 在 EC2 实例中创建日志文件
- mongodb - Mongoose 使用聚合/填充查询参考集合数据
- ios - 解析没有键的Json数组swift 4
- swift - 在 Realm 中存储通用子类
- javascript - 如何用玩笑测试传递给 document.body.appendChild 的参数
- apache-spark - 为什么 Spark 工作节点上完成的任务比主节点少得多?
- node.js - 带有 fs、缓冲区和流的 TypeORM 错误
- haskell - 镜头访问地图键
- python - Python GraphQL API 调用组合