Yii2 GridView 自定义标题行 [英] Yii2 GridView Customize Header Row

查看:29
本文介绍了Yii2 GridView 自定义标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的视图代码中,我有这个:

In my view code I have this:

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yiigridSerialColumn'],
             ['label' => 'Training Score',
               'attribute' => 'scoreTraining',
               'format' => ['decimal',2],
             ],
             ['label' => 'Exam Score',
               'attribute' => 'scoreExam',
               'format' => ['decimal',2],
             ],
        ],
    ]);

通常标题名称为Training Score"和Exam Score"

Normally the header name will be "Training Score" and "Exam Score"

在 yii2 gridview 中可以自定义标题行吗?所以我的标题行看起来像 2 行..

Is that possible in yii2 gridview to customize the header row? so that my header row looks like in 2 line..

<table border=1>
  <tr><th>Training <br> Score</th><th>Exam <br> Score</th></tr>
</table>

推荐答案

要实现这一点,请使用 header 属性而不是 label :

To achieve that, use header property instead of label:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        ['class' => 'yiigridSerialColumn'],
        [
            'header' => 'Training <br> Score',
            'attribute' => 'scoreTraining',
            'format' => ['decimal', 2],
        ],
        [
            'header' => 'Exam <br> Score',
            'attribute' => 'scoreExam',
            'format' => ['decimal', 2],
        ],
    ],
]);

这样 HTML 内容就不会被编码.

That way HTML content won't be encoded.

官方文档:

这篇关于Yii2 GridView 自定义标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆