3

I'm Using Kartik's GridView Widget,

GridView::widget([
            'id'=>'crud-datatable',
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'pjax'=>true,
            'contentOptions' => ['class' => 'form-control punjabi'],
            'headerOptions' => ['class' => 'text-center'],
            'columns' => require(__DIR__.'/_columns.php'),
])

In yii\grid\GridView class, It can be done with the following options :

[
    'contentOptions' => ['class' => 'text-center'],
    'headerOptions' => ['class' => 'text-center']
],

But using the above options in Kartik's GridView Class generates error: Undefined Property contentoptions.

How to go About this?

2
  • 1
    use containerOptions. Commented Apr 13, 2016 at 10:39
  • just for information, which class is $containerOptions a property of kartik\grid\GridView or yii\grid\GridView? Commented Apr 13, 2016 at 11:31

1 Answer 1

3

contentOptions is an attribute of yii\grid\Column not of yii\grid\GridView. The classes need to be applied to the columns i.e.

GridView::widget([
    ... //Other options here
    'columns' => [
        [
            'attribute' => 'name',
            'contentOptions' => ['class' => 'form-control punjabi'],
            'headerOptions' => ['class' => 'text-center'],
        ]
    ]
]

If you would like to apply the same style to all the cells you can create your own column class, set defaults for contentOptions and headerOptions, and use that class instead of yii\grid\DataColumn.

Sign up to request clarification or add additional context in comments.

2 Comments

$headerOptions only styles the Header. How do I edit the css of the Filter Cells?
When in doubt refer to the manual: $filterOptions or $filterInputOptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.