M
M
Monitorkin2019-07-18 13:45:18
Yii
Monitorkin, 2019-07-18 13:45:18

How to display glyphicon fontawesome instead of glyphicon icons in yii2 gridview?

How to display fontawesome instead of glyphicon icons in gridview yii2 that are displayed by default
?
Because I want fontawesome! :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-07-20
@Monitorkin

There are several options here:
1. Create your own ActionColumn class and inherit it from the base ActionColumn . In this class, override the desired implementation. As Dmitry Derepko
advises 2. Replacement in one place. If you need to replace only in one place, it makes sense to use Dmitry
's solution 3. Combine all this using a DI container. I always recommend using such a global data substitution. It's more flexible. To do this, we create a Bootstrap class with the implementation of the \yii\base\BootstrapInterface interface . We connect it to the application startup (bootstrap in config.php) and replace everything we need:

$actionColumnSetting = [
            'buttons' => [
                'view' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-eye" aria-hidden="true"></i>', ['update']);
                },
                'update' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-pencil-alt" aria-hidden="true"></i>', ['update']);
                },
                'delete' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-trash" aria-hidden="true"></i>', ['delete']);
                }
            ],
        ];
        \Yii::$container->set(ActionColumn::class, $actionColumnSetting);

It is convenient in all cases. For example, you suddenly want to use other editing actions in all gridviews. It will be easy to replace. You need to rename update to edit. Or you need an additional "move archive" button in all gridviews
$actionColumnSetting = [
            'buttons' => [
                'view' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-eye" aria-hidden="true"></i>', ['edit']);
                },
                'update' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-pencil-alt" aria-hidden="true"></i>', ['update']);
                },
                'delete' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-trash" aria-hidden="true"></i>', ['delete']);
                },
  'archive' => function($name, $model, $key){
                    return Html::a('<i class="fas fa-trash" aria-hidden="true"></i>', ['archive']);
                }
            ],
        ];
        \Yii::$container->set(ActionColumn::class, $actionColumnSetting);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question