I have a Gridview with three columns. The Query column is a PostgreSQL TEXT type and has 9 lines in this example.
I would like to show only the first 4 lines for all rows else my table will be too big.
I have a Gridview with three columns. The Query column is a PostgreSQL TEXT type and has 9 lines in this example.
I would like to show only the first 4 lines for all rows else my table will be too big.
Display text based on the number of specified lines.
Assuming that the text in the DB with
Saved. too \n
You do it according to the necessary separator.... <br>
or <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]);
},
],
Display text based on the number of specified characters
[
'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))." ...";
},
],
Display text based on element width. max-width
[
'contentOptions' => ['style' => 'text-overflow: ellipsis; white-space: nowrap; max-width: 25vw; overflow: hidden;'],
'attribute' => 'text',
'value' => function ($model) {
return $model->text;
},
],
display Text based on height
Note: Change the height according to your font and requirements.
[
'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>';
},
],