Answer the question
In order to leave comments, you need to log in
How to shorten long text in GridVIew?
how to shorten long text in yii2 admin in gridview?
Answer the question
In order to leave comments, you need to log in
All $data
properties are stored in, the function mb_substr
cuts the string to the required number of characters, if the length of the source text is less than the specified one, then we output it without changes, otherwise we print the shortened string.
Substitute myattribute
your attribute.
[
'attribute' => 'myattribute',
'value' => function($data) {
$charsCount = 100;
$croppedText = mb_substr($data->text, 0, $charsCount);
return mb_strlen($data->text) > 100 ? $croppedText : $data->text;
}
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question