【问题标题】:How to fix the Column size of CGRIDVIEW in YII?如何修复 YII 中 CGRIDVIEW 的列大小?
【发布时间】:2014-05-27 10:55:30
【问题描述】:

我想修复 GridView 的列宽。当我使用 GridView 时,列的宽度会根据数据进行调整......我的目标是为每一列设置一个固定的宽度,例如:对于“ID”列,我想要 width=10px;对于“名称”列,它应该是 width=50px ...等等

视图是

if(!empty($selected_columns))
    {
        $this->widget('bootstrap.widgets.TbGridView', array(
            'type' => 'bordered striped',
            'id' => 'bike_search_grid',   
            'dataProvider' => $model->search_bike(),
            'ajaxUpdate' => true, //false if you want to reload aentire page (useful if sorting has an effect to other widgets)
            'filter' => null, 
            'template'=>'<div style="overflow:auto;">{items}</div>{pager}{summary}',
            'columns' => $selected_columns,
            'enablePagination' => true
        ));
    }

已编辑 :::

模型是

$selected_columns = array();
$selected_columns[] = array(
                'header' => 'ID',
                'name' => 'bike_id',
                'value'=>'$data["bike_id"]', 
                'htmlOptions'=>array('width'=>'30'),
                'headerHtmlOptions'=>array('width'=>'30')
            );

【问题讨论】:

    标签: php gridview yii dataprovider cgridview


    【解决方案1】:

    $selected_colums 的格式不正确。试试这个:

    $selected_columns[] = array(
               array(
                    'header' => 'ID',
                    'name' => 'bike_id',
                    'value'=>'$data["bike_id"]', 
                    'htmlOptions'=>array('width'=>'10'),
                    'headerHtmlOptions'=>array('width'=>'10')
                    ),
                );
    

    要显示的每一列都应以 array('key'=>'value') 格式提供

    【讨论】:

    • --> 嗨 .. 请检查编辑的部分 .... 它的正确放置... i jss 以前没有包含... 并且提供的代码没有给我结果跨度>
    【解决方案2】:

    解决方案:=>

    查看:

    $this->widget('bootstrap.widgets.TbGridView', array(
                'type' => 'bordered striped',
                'id' => 'bike_search_grid',   
                'dataProvider' => $model->search_bike(),
                'ajaxUpdate' => true, //false if you want to reload aentire page (useful if sorting has an effect to other widgets)
                'filter' => null, 
                'template'=>'<div style="overflow:auto;">{items}</div>{pager}{summary}',
                'columns' => $selected_columns,
                'enablePagination' => true
            ));
    

    型号:

      $selected_columns[] = array(
                        'header' => 'ID',
                        'name' => 'bike_id',
                        'type'=>'html',
                        'htmlOptions'=>array('style'=>'word-wrap: break-word;'),
                        'headerHtmlOptions'=>array('style'=>'text-align:center;'),
                        'value'=> '"<div style=\"width:90px;\">" . $data["bike_id"] . "</div>"',
                                      );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多