我是yii2的新手..如何将css应用于yii2 gridview的列标题,列标题?
<?php
$gridColumns = [
['class' => 'yii\grid\SerialColumn'],
['class' => 'yii\grid\CheckboxColumn'],
'name',
'company_mail', //change the color of heading
'no_employees',
'email:email',
.
.
.];
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
]);
?>
答案 0 :(得分:2)
您可以使用这种方式设置特定的列样式/ css。
$columns = [
'onenormalcolumn',
'anothercolumn',
[
'format'=>"ntext", // or other formatter
'attribute' => 'theattributeofmodel',
'contentOptions' => ['style' => 'width:50px'], // For TD
'headerOptions' => ['class' => 'ur-class'] // For TH
]
]
答案 1 :(得分:0)
您必须在详细模式下设置列:
<?php
$columns = [
'onenormalcolumn',
'anothercolumn',
[
'format'=>"ntext", // or other formatter
'attribute' => 'theattributeofmodel',
'options'=>[ 'style'=>'your rules here' ]
]
]
?>
答案 2 :(得分:0)
如果要更改列标题css属性,则应使用headerOptions列propreties,例如:
'columns' => [
['class' => 'yii\grid\SerialColumn'],
.......
'anothercolumn',
[
'format'=>"ntext", // or other formatter
'attribute' => 'theattributeofmodel',
'headerOptions'=>[ 'style'=>'background-color:#ccf8fe' ]
],
],