如何在yii2中设置gridview的宽度

时间:2017-10-30 11:09:18

标签: php yii2

如何在视图yii2中设置gridview列的宽度, 参考链接如下,

2 个答案:

答案 0 :(得分:4)

试试这个,

<?=
    GridView::widget([
        'model' => $model,
        'options' => ['style' => 'width:80%'],
        'attributes' => [
            'id',
        ],
    ])
?>

答案 1 :(得分:0)

单独设置一列的宽度,如下所示:

[
    'attribute' => 'attribute_name',
    'headerOptions' => ['style' => 'width:20%'],
],

对于所有列,请尝试:

[ 
    'class' => 'yii\grid\SerialColumn', 
    'contentOptions' => ['style' => 'width:100px;'], 
],