Yii CGridView change column width for raw type cell

I am using Yii 1.1 CGridView with ‘raw’ cell type. The cell contains text field generated using CHtml::textField. Here I cannot change the width of the column using headerHtmlOptions or htmlOptions. Please help.




$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'),

    ))



I added




"style"=>"width:100%"



in CHtml::textField htmlOptions and was able to change the width of column

Hi, I’ve just arrived to the forum. You already found the answer by yoursel, that’s cool. I see you like to use all the possible settings the widget brings to the coders, that’s great. I just recommend you to try to distribute in a more balanced way the config elements, not to put everything directly in the view… this is just a little friendly tip, anyway good work bro… keep going and good luck…