如何将css应用于特定列的gridview列中yii2
问题描述:
我是yii2的新手。如何将css应用于列,列标题yii2 gridview?如何将css应用于特定列的gridview列中yii2
<?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,
]);
?>
答
您可以使用这种方式设置特定的列样式/ css。
$columns = [
'onenormalcolumn',
'anothercolumn',
[
'format'=>"ntext", // or other formatter
'attribute' => 'theattributeofmodel',
'contentOptions' => ['style' => 'width:50px'], // For TD
'headerOptions' => ['class' => 'ur-class'] // For TH
]
]
答
你必须设置在详细模式下你的专栏:
<?php
$columns = [
'onenormalcolumn',
'anothercolumn',
[
'format'=>"ntext", // or other formatter
'attribute' => 'theattributeofmodel',
'options'=>[ 'style'=>'your rules here' ]
]
]
?>
答
,如果你想更改列标题的CSS属性,你应该使用headerOptions列propreties如:
'columns' => [
['class' => 'yii\grid\SerialColumn'],
.......
'anothercolumn',
[
'format'=>"ntext", // or other formatter
'attribute' => 'theattributeofmodel',
'headerOptions'=>[ 'style'=>'background-color:#ccf8fe' ]
],
],
我不想直接使用..想给ID或类......然后应用CSS样式..你可以帮助?? .....我也试过这样... https: //stackoverflow.com/questions/39241292/how-to-change-color-of-header-for-all-gridview-in-yii2 ....但它适用于表格的内容而不是标题 – Goli
替换'样式'在示例中使用'class',并将您的类名设置为值。 – Prescol
'选项'=> [ '类'=> 'YourCustomTableClass', ], 2)添加新的样式规则到它(在CSS文件): .YourCustomTableClass { 颜色:#FF0000; } ...............不改变列HEADING的颜色..只改变表格内容的颜色/ ROWS – Goli