hidden values in CGridView


how can I hide values in CGridView ??

I already tried to hide a column like this:


it works but the Column header is still visible.

then I tried to put values into hidden fields inside a template:


'template'=>'{myButton}<input type="hidden" name="hid" value="'.$data->hid.'">',

but at this point the $data->hid is empty. WHY?

thx in advance.

$data has a meaning only in some property, for example il CDataColumn::value.

Try in some column to use:

'value'=>'$data-> field <input type="hidden" name="hid" value="'.$data->hid.'">'


Type row will avoid html encoding of the cell.

i could do something like this:


'type'=> 'raw',

'value'=> 'CHtml::hiddenField("hid", $data->tarif_id)', 


but then there’s an empty cell,

and i dont know how to add an additional value next to the hidden field.

Hi tofu2000,

I have done it using following method



  [b]'htmlOptions'=&gt;array([color=&quot;#FF0000&quot;]'style'=&gt;'width:0%; display:none'[/color]),[/b]

  [b]'headerHtmlOptions'=&gt;array([color=&quot;#FF0000&quot;]'style'=&gt;'width:0%; display:none')[/color]),[/b]

It worked without displaying any column header.

Thank you,


tnx works!!!

This works if we have a few hidden columns. However, when there are many hidden columns, the CGridView becomes like this:

As you can see, there is a blank space on the right part of it. Does someone have alternative solution to hide CGridView column (without losing its value)?

Try this… there should no more blank space on the hidden column.





'htmlOptions'=>array('style'=>'width:0%; display:none'),


Thanks for your reply, but I had tried that before and got the same result. Perhaps the solution is to use 1 hidden column, as described in this thread.

Hello, I am newbie in yii…

tx for the solution …

it work …

We need to have hidden fields in our columns for id columns in the database which can be accessible in the $_REQUEST so database can be manipulated. For this there is a simple solution which is as follows:

In any column which is visible to user one can have many hidden fields using the concatenation operator:






            'CHtml::hiddenField(\'array_available_in_request[\'.$row.\']["id"]\', $data["id"]) .

            CHtml::hiddenField(\'array_available_in_request[\'.$row.\']["parent_id"]\', $data["ParentId"]) .

            CHtml::textField(\'array_available_in_request[\'.$row.\']["field_name"]\', $data["field_name"], array("style"=>"width:50px;"));'


I found this worked for me.

Just wanted to hide the id column but still wanted to be able to click on the row and go to the record view


	'name' =&gt;  'id',

	'type'=&gt; 'raw',

//      'value'=&gt; 'CHtml::hiddenField(&quot;id&quot;, &#036;data-&gt;id)',

	'value'=&gt; '&#036;data-&gt;id', 

//	'header'=&gt;false,

//	'filter'=&gt;false,

	'headerHtmlOptions'=&gt;array('style'=&gt;'width:0%; display:none'),

	'filterHtmlOptions'=&gt;array('style'=&gt;'width:0%; display:none'),

	'htmlOptions'=&gt;array('style'=&gt;'width:0%; display:none'),


The key was the filterHtmlOptions…before adding that it seemed to have a shift in the columns / filters and headers so

they did not match up.

Thanks it works.