A
A
akula222017-02-08 10:44:13
Yii
akula22, 2017-02-08 10:44:13

How to insert icon and value into label in gridview?


How to insert an icon and value something like this in the gridview in the label , but it does not work

[
                            'attribute' => 'user_id',
                            'label' => function ($data) {
                                return '<i class="fa fa-user-circle" aria-hidden="true"></i>' . $data->user_id;
                            },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-02-08
@qonand

first, if you use the standard \yii\grid\DataColumn then the label property cannot accept an anonymous function. Secondly, in order to display the html content correctly, you need to set the encodeLabel parameter to false
. For example, like this:

[
    'attribute' => 'user_id',
    'label' => '<i class="fa fa-user-circle" aria-hidden="true"></i>',
    'encodeLabel' => false
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question