2017-10-28 50 views
0

我是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, 
    ]); 
    ?> 

回答

0

您可以使用这种方式设置特定的列样式/ css。

$columns = [ 
    'onenormalcolumn', 
    'anothercolumn', 
    [ 
     'format'=>"ntext", // or other formatter 
     'attribute' => 'theattributeofmodel', 
     'contentOptions' => ['style' => 'width:50px'], // For TD 
     'headerOptions' => ['class' => 'ur-class'] // For TH 

    ] 
] 
0

你必须设置在详细模式下你的专栏:

<?php 
$columns = [ 
    'onenormalcolumn', 
    'anothercolumn', 
    [ 
     'format'=>"ntext", // or other formatter 
     'attribute' => 'theattributeofmodel', 
     'options'=>[ 'style'=>'your rules here' ] 
    ] 
] 
?> 

Yii2 Gridview column options

+0

我不想直接使用..想给ID或类......然后应用CSS样式..你可以帮助?? .....我也试过这样... https: //stackoverflow.com/questions/39241292/how-to-change-color-of-header-for-all-gridview-in-yii2 ....但它适用于表格的内容而不是标题 – Goli

+0

替换'样式'在示例中使用'class',并将您的类名设置为值。 – Prescol

+0

'选项'=> [ '类'=> 'YourCustomTableClass', ], 2)添加新的样式规则到它(在CSS文件): .YourCustomTableClass { 颜色:#FF0000; } ...............不改变列HEADING的颜色..只改变表格内容的颜色/ ROWS – Goli

0

,如果你想更改列标题的CSS属性,你应该使用headerOptions列propreties如:

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

    ....... 
    'anothercolumn', 
     [ 
     'format'=>"ntext", // or other formatter 
     'attribute' => 'theattributeofmodel', 
     'headerOptions'=>[ 'style'=>'background-color:#ccf8fe' ] 
     ], 

],