如何将 css 应用于 yii2 中 gridview 列的特定列

Gol*_*oli 4 gridview yii2

我是 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,
    ]); 
    ?>
Run Code Online (Sandbox Code Playgroud)

小智 6

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

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

   ]
]
Run Code Online (Sandbox Code Playgroud)