2015-10-29 181 views
-1

我正在使用'raw'單元格類型的CGridView。該單元格包含使用CHtml :: textField生成的文本字段。在這裏,我無法使用headerHtmlOptions或htmlOptions來更改列的寬度。請幫忙。CGridView更改原始類型單元格的列寬

$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

您的代碼包含錯誤。像'array(name =>'length''必須是'array('name'=>'length')'。同樣請格式化你的代碼以便讀取。也可以顯示完整的css應用於表。也許'table {table-佈局:固定;}'可能會幫助 – Justinas

+0

@Justinas更新答案 – user1690835

回答

0

我了CHtml ::文本框htmlOptions添加

"style"=>"width:100%" 

,並能夠更改列的寬度

相關問題