如何在GridView中为<td>标签添加类?

31

我需要给 GridView 的 td 添加类。我找到了 renderTagAttributes(),但是我找不到如何使用它的示例。

您能为我解释一下这个函数或者提供其他选项吗?

我的 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}',
        ]
    ],
]); ?>

提前致谢

1个回答

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

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

参考:Yii2 文档 | GridView 中的列类


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接