如何在 GridView 中添加 class 到 <td> 标签

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

我需要将 类 添加到 GridView 的 td。 我找到了 renderTagAttributes(),但找不到如何使用它的示例。 你能给我解释一下这个功能或给我其他选择吗?

我的网格视图:

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

提前致谢

例如

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

contentOptions - 对于 td 单元格,headerOptions - 对于 th 单元格

参考:Yii2 Docs | Column classes in GridView