CGridView更改原始类型单元格的列宽

时间:2015-10-29 11:43:09

标签: html yii

我正在使用CGridView' raw'细胞类型。单元格包含使用CHtml :: textField生成的文本字段。在这里,我无法使用headerHtmlOptions或htmlOptions更改列的宽度。请帮忙。

$this->widget('zii.widgets.grid.CGridView', array(
                    'id'=>'mbook-grid',
                    'itemsCssClass'=>'table table-bordered table-condensed table-hover table-striped dataTable',
                    'dataProvider'=>$model->search(),
                    'afterAjaxUpdate'=>'calcquantity',
                    'enablePagination' => true,
                    'pagerCssClass'=>'dataTables_paginate paging_bootstrap table-pagination',
                    'pager' => array('header'=>'','htmlOptions'=>array('class'=>'pagination')),
                    'columns' => array(

                                        array(
                                        'class' => 'CCheckBoxColumn',
                                        'id'=>'project_estimate_id',
                                        'htmlOptions'=>array('style' => 'display:none'),
                                        'headerHtmlOptions'=>array('style' => 'display:none'),    
                                        'selectableRows'=>2,
                                        'value'=>'$data["project_estimate_id"]',
                                        'checked'=>'true',
                                        ),
                                        array('name'=>'description','value'=>'CHtml::textField("ProjectMBookGrid[description_".$data["project_estimate_id"]."]",$data["description"],array("class"=>"gridfield"))','type'=>'raw','header'=>'Description','headerHtmlOptions'=>array('style'=>'width: 5%;')),
                                        array('name'=>'length','value'=>'CHtml::textField("ProjectMBookGrid[length_".$data["project_estimate_id"]."]",$data["length"],array("class"=>"gridfield","style"=>"text-align: right"))','type'=>'raw','header'=>'Length','headerHtmlOptions'=>array('style'=>'width:5%')),
                                        array('name'=>'breadth','value'=>'CHtml::textField("ProjectMBookGrid[breadth_".$data["project_estimate_id"]."]",$data["breadth"],array("class"=>"gridfield","style"=>"text-align: right"))','type'=>'raw','header'=>'Breadth','htmlOptions'=>array('style'=>'text-align: right')),
                                        array('name'=>'quantity','value'=>'CHtml::textField("ProjectMBookGrid[quantity_".$data["project_estimate_id"]."]",$data["quantity"],array("class"=>"gridfield","style"=>"text-align: right"))','type'=>'raw','header'=>'Quantity','htmlOptions'=>array('style'=>'text-align: right')),

                        ),
                            'htmlOptions'=>array('class'=>'grid-view table-responsive hide-x-scroll'),
                )) 

以下是CSS

.table.dataTable {
    clear: both;
    margin-bottom: 10px;
}

.table-bordered.dataTable {
    border-top: 1px solid #ddd;
}

table {
    background-color: transparent;
    max-width: 100%;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

.hide-x-scroll {
    overflow-x: scroll;
}
.grid-view {
    padding: 15px 0;
}

1 个答案:

答案 0 :(得分:0)

我添加了

"style"=>"width:100%"

在CHtml :: textField htmlOptions中,并且能够更改列的宽度