How do you add a button to a CGridView?

cbuttoncolumn, cgridview, yii

Solution

Try this:

$dataProvider = new CArrayDataProvider ($auctions);
$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
  'columns'=>array(
    'id::ID',
    'product.title::Title',
    'state::Status',
     array(
         'type' => 'raw',
         'value' => '<button onclick=\'alert("It works!")\' value="clickme"/>'
     )
  ),
));

Problem

Sounds simple, right? I've searched high and low and I can't find out how to do this. I have a CGridView: ``` $dataProvider = new CArrayDataProvider ($auctions); $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'columns'=>array( 'id::ID', 'product.title::Title', 'state::Status', ), )); ``` I want to add a fourth column that only contains a simple button that will execute javascript when pressed. I've tried: ``` array( 'class' => 'CButtonColumn', ), ``` This just gives me an error: ``` Undefined property: stdClass::$primaryKey ``` Any ideas?

Original source