Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put custom HTML into Yii2 GridView header?

There's this <abbr></abbr> tag in bootstrap that will automatically shows popup of the abbreviated word. I want to insert this tag to a certain header in the gridview with attribute name act. Here is my code so far.

        [
            'attribute'=>'act',
            'format'=>'raw',
            'label'=>'<abbr title="Area Coordinating Team">ACT</abbr>',
            'value'=>function($model){
              return '<span class="fa fa-thumbs-up text-green"></span>';
            }
        ],

but the output literally shows the whole <abbr title="Area Coordinating Team">ACT</abbr>

enter image description here

like image 383
beginner Avatar asked Apr 30 '15 08:04

beginner


People also ask

What is GridView in yiiframework 2?

Yii Framework 2 : Gridview. In yiiframework 2.0, The gridview widget is used to display the data like image, text, etc in a grid. It is having a lot features like sorting, pagination, filtering, styling etc. This widgets is mostly used by developers.

How to create a custom yii2 widget?

Let's review basic steps of creating a custom Yii2 widget firstly. Override init and run method of yii\base\Widget. init is used to do some initializing work, run is responsible for rendering the view of a widget. In earlier basic tutorial, we do lots of HTML echoing work in run method.

How to set HTML attributes for'GridView'table cells in yii2?

Configure the gridview button or template, header lable value and button options like class, style etc. Add the new button in gridview action template and configure the url, text, title etc. If we would like to set the HTML attributes for 'Gridview' table cells in yii2.0, Just use the 'contentOptions' parameter for that cell.

How to show/hide the summary text of GridView table in yii2?

Show/Hide the summary text, footer and header of gridview table yii2.0. Hide the gridview using 'showOnEmpty' properties If the data is not available to show in gridview table. Every developer would like to play with gridview action. I added the code for that from my experience.


Video Answer


1 Answers

I already answered that here.

To achieve that, use header property instead of label:

[
    'attribute' => 'act',
    'format' => 'raw',
    'header' => '<abbr title="Area Coordinating Team">ACT</abbr>',
    'value' => function ($model) {
        return '<span class="fa fa-thumbs-up text-green"></span>';
    },
],

That way HTML content won't be encoded.

Official docs:

  • $header
like image 129
arogachev Avatar answered Nov 11 '22 01:11

arogachev