Normal Button In Cgridview

Hi there,

I am trying to put in just a regular <button> element into a column in CGridView. If I use this:


array(

    'header' => '&nbsp;',

    'value' => 'CHtml::tag("button", array(

        'type' => 'button',

        'class' => 'btn',

    ), "Edit")',

    'type' => 'html',

),

It strips out the HTML leaving just “Edit” in the <td></td>. If I use the CHtml::button() method, nothing appears. If I use ‘type’ => ‘text’, then it HTML encodes the string and the actual HTML is seen in the cell.

I thought maybe CButtonColumn would be the answer, but these "buttons" are really link images.

How can I place a <button> element in the cell?

Thank you!

i don’t know i understood you properly or not? :unsure: but i think you want to add new button in CGridView. if you are looking for this then you can add button by adding following code.




$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'appliedjobs-grid',

	'dataProvider'=>$model->search(),

	//'filter'=>$model,

	'columns'=>array(

                   array(

  	             'class'=>'CButtonColumn',

                     'template'=>'{show}',

                     'buttons'=>array(

                     'show'=>array(

                     'label'=>'Show',

                     'imageUrl'=>Yii::app()->request->baseUrl.'/images/viewimg.png',

                     'url'=>'Yii::app()->createAbsoluteUrl("Jobpost/pview",array("id"=>$data->JobId))',

                    ),),

                ),

             ),

          )



hope it may help you…

jreznik,

What happens if you set the ‘type’ as ‘raw’?

The CButtonColumn is very flexible. You can customise those links or add new ones, as kalpit explained. This tutorial describes the flexibility of the CButtonColumn.

You can use :

array(

	    'header'=&gt;&quot;Header Text&quot;,


	    'type'=&gt;'html',


	    'value'=&gt;'CHtml::link(getStatus(), Yii::app()-&gt;createUrl(Path of controller))',


	    'htmlOptions'=&gt;array('style'=&gt;'text-align:center;width:80px;')


	),

Outside Grid:

function getStatus($type)

{

	return  '&lt;button type=&quot;submit&quot;&gt;&lt;/button&gt;';


    }

}

check this wiki

This is the correct answer! Don’t know how I missed the ‘raw’ type, but that got the button in there.

Thanks, BlkRaven!