如何更改yii2中所有gridview的标题颜色? [英] how to change color of header for all gridview in yii2?

查看:308
本文介绍了如何更改yii2中所有gridview的标题颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为yii2中所有的 GridView 标题更改标题的背景颜色。我知道下面的代码可以实现这个功能,但我只需要在代码中更改一次,即所有相同颜色的标题。

 <?= GridView :: widget([
'dataProvider'=> $ dataProvider,
'filterModel'=> $ searchModel,

'columns'=> [
['class'=>'yii\grid\SerialColumn'],

[
'属性'=>'user_id',
'headerOptions'=> ['style'=&'background-color:#ccf8fe'],
],
],
]); ?>

我该怎么办?

解决方案

为每列添加样式选项似乎是唯一的方法,但我无法保证。但是,你并不仅限于此。解决方案解决方案:

1)将此代码添加到 GridView :: widget 的某处(例如, columns => [...]


  // ... 
'filterModel'=> $ searchModel,
'options'=> [
'class'=>'YourCustomTableClass',
],
// ...

2)为它添加新的样式规则(在 css file):

  .YourCustomTableClass表格thead {
background-color:#FF0000;
}

CSS将为每列中的标题应用背景色(红色)。我已经亲自测试过,以确认它是否有效。


I want to change background color of header for all my GridView headers in yii2. I know the following code does this work but I want change only once in code, all header of the same color.

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,

    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        [
            'attribute' => 'user_id',
            'headerOptions' => ['style' => 'background-color:#ccf8fe'],
        ],
    ],
]); ?>

What should I do?

解决方案

Adding style options to each column seems to be the only way, but I can't guarantee. However, you're not limited to only that. The workaround solution:

1) Add this code somewhere in GridView::widget (for example, above columns => [...]:

 // ...
 'filterModel' => $searchModel,
 'options' => [
    'class' => 'YourCustomTableClass',
 ],
 // ...

2) Add new style rules to it (in css file):

.YourCustomTableClass table thead {
    background-color: #FF0000;
}

CSS will apply background color (red) for header in each column. I have tested this myself to confirm it works.

这篇关于如何更改yii2中所有gridview的标题颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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