D
D
djienbaev972020-01-18 11:24:15
Yii
djienbaev97, 2020-01-18 11:24:15

How to shorten long text in GridVIew?

how to shorten long text in yii2 admin in gridview?5e22c0ac59e6b056378369.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Musonov, 2020-01-18
@djienbaev97

All $dataproperties are stored in, the function mb_substrcuts 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 myattributeyour 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 question

Ask a Question

731 491 924 answers to any question