Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a class to <td> tags in a GridView

Tags:

gridview

yii2

I need to add classes to td of a GridView. I've found renderTagAttributes(), but I can't find examples how to use it. Could you explain me this function or offer me other option?

My gridview:

 <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'id',
        'name',
        'price',
        'quantity',
        'created_at',
        [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{update} {delete}',
        ]
    ],
]); ?>

Thanks in advance

like image 818
Kevin7 Avatar asked Apr 09 '15 14:04

Kevin7


1 Answers

For example

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

contentOptions - for td cells, headerOptions - for th cells

Reference: Yii2 Docs | Column classes in GridView

like image 177
Alex Avatar answered Nov 05 '22 04:11

Alex