本文介绍了如何把自定义的HTML到Yii2的GridView头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bootstrap中有< abbr>< / abbr> 标记,它会自动显示缩略词的弹出窗口。我想插入这个标签到属性名为 act 的gridview中的某个头部。这是我的代码到目前为止。

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






$ p $但是输出字面上显示整个< abbr title =区域协调小组> ACT< / abbr> $ b

解决方案

我已经回答那。



为了达到这个目的,使用标题属性而不是 label

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

这样HTML内容将不会被编码。



官方文档: href =http://www.yiiframework.com/doc-2.0/yii-grid-column.html#$header-detail =nofollow noreferrer> $ 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>

解决方案

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:

这篇关于如何把自定义的HTML到Yii2的GridView头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:05