2017-10-28 55 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' ] 
     ], 

], 
相關問題