Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是的。如何仅为GridView小部件中的特定列指定宽度?_Php_Gridview_Yii2 - Fatal编程技术网

Php 是的。如何仅为GridView小部件中的特定列指定宽度?

Php 是的。如何仅为GridView小部件中的特定列指定宽度?,php,gridview,yii2,Php,Gridview,Yii2,我需要为特定列指定宽度(例如“文件名”)。我尝试过一些建议,但对我不起作用 一个可能的解决方案是使列的大小可调整,但我也不知道如何做 <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions'=>['class'=>'table-striped table-bordered table-condens

我需要为特定列指定宽度(例如“文件名”)。我尝试过一些建议,但对我不起作用

一个可能的解决方案是使列的大小可调整,但我也不知道如何做

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'tableOptions'=>['class'=>'table-striped table-bordered table-condensed'],
    'options'=>['style' => 'white-space:nowrap;'],
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'lastname',
        'firstname',
        'middlename',
        'rs_account',
        'sum',
        'file_name',
        'state',
        'history_id',
        [
            'label' => 'Code',
            'attribute' => 'codes.code',
        ],
        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>

对于要设置样式的每个属性,都应该使用contentOptions

<?= GridView::widget([
  'dataProvider' => $dataProvider,
  'filterModel' => $searchModel,
  'tableOptions'=>['class'=>'table-striped table-bordered table-condensed'],
  'options'=>['style' => 'white-space:nowrap;'],
  'columns' => [
      ['class' => 'yii\grid\SerialColumn'],
      'lastname',
      'firstname',
      'middlename',
      'rs_account',
      'sum',

      ['attribute' => 'file_name',
         'label' =>'Filename'
         'contentOptions' => ['style' => 'width:680px;  min-width:600px;  '],
      ],
      'state',
      'history_id',
      [
          'label' => 'Code',
          'attribute' => 'codes.code',
      ],
      ['class' => 'yii\grid\ActionColumn'],
  ],
]); ?>

使用头部选项:

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

我已经多次测试了这段代码。。你有错吗。结果不是你所需要的?请解释一下“不工作”是什么意思1.这一栏的宽度等于它的内容。当我编写代码时,将列宽指定为30px并刷新页面,但没有任何更改。它也不起作用。我不知道为什么。如果我改变了表格选项,它就会起作用。但应用于特定字段的更改被忽略。谢谢你的关心!只是为了测试。。。尝试不在表格选项中压缩表格您可以尝试使用最小宽度或最大宽度-width@Kevin想知道你是否解决了这个问题problem@Kevin不幸的是,没有。现在我没有获得源代码,也无法测试其他可能的解决方案。