Search code examples
yii2kartik-v

HTML in YII2 Kartik Gridview column label (not heading)


I have a Kartik gridview in YII2 and I need to be able to put HTML into the label (not header, I'll come to that) of a column.

My column definition is as such

        [
            'attribute' => 'picked_percent',
            'format' => 'raw',
            'label' => 'P<span class="responsive">icked</span>',
        ],

But if I do this, it outputs

P&lt;span class=&quot;drawn_head&quot;&gt;icked &lt;/span&gt;

I can change label to header and it looks fine but I need it to be clickable and it isn't when I change it to header.

I've also tried changing the format from raw to HTML and that makes no difference.

Any help is much appreciated.


Solution

  • If you want the label to not be encoded you need to add this config option in the column definition array:

    'encodeLabel' => false