Display html in CGridView

How can I insert and output html tags in CGridView rows?

Yes, you have to set the ‘type’ of the datacolumn to ‘raw’.

See this forum topic.

just specify "type" of data to "raw" and it will not be escaped (look at second attribute in example below):




'columns'=>array(

	'some_attribute',

	array( 'name'=>'html_attribute', 'type'=>'raw' ),

	'another_attribute',

	array(

		'class'=>'cs.grid.CSButtonColumn',

	),

),



This should be the proper way. It has worked for me well .





'type' => 'raw',

'value'=>function($data){

  return '<div id="Div1" class="checkBox margin10 Div1"></div>';

},




You may can use a php function inside the the c grid view


array('name'=>'',

      'header'=>'Type',

      'type' => 'raw',

      'value'=>'get($data)',

     ),

PHP Function


function get($data)

{

    //html tags..

}

Another Example.

[i][b]<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

         'id'=&gt;'carservicetype-grid',


         'dataProvider'=&gt;&#036;model-&gt;search(),


         'filter'=&gt;&#036;model,


         'columns'=&gt;array(


	         'id',


	         'slug',


                     array(


                              'name'=&gt;'',


                              'value'=&gt; function(){ return CHtml::image(Yii::app()-&gt;baseUrl.'/images/link.png', '.jpg'); },


                              'type'=&gt;'html',

filter’=>false,

                      ),


	   array(


		           'class'=&gt;'CButtonColumn',


	   ),


),

)); ?>[/b][/i]

Best Regards www.iSystems.am

all U need is to set ‘type’ in column setup, something like :

array(‘name’=>‘attribute’,

  'header'=&gt;'label',


  'type' =&gt; 'raw',


  'value'=&gt;'your html',


 ),
1 Like

… or simply:


 'columns' => array(

                'note:html',

                // [...],

              )