Hi all, i’m trying edit de buttons in CGridView(edit,delete,view) and when you click over this(edit,delete,view) i need launch a js script using the current id of de “row”, i try get the value using $data->id but isn’ts work (sorry for my english is so bad…)
here some of code of the view
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'vehicle-grid',
'htmlOptions' => array(),
'cssFile' => false,
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
....
array(
'class' => 'CButtonColumn',
'buttons'=>array(
'update' => array(
'label'=>'Editar', // text label of the button
'url'=>'Yii::app()->createUrl("vehicle/update",array("id"=>$data["id"]))',// a PHP expression for generating the URL of the button
'options'=>array('onClick'=>'openUpdateDialog();return false;'), // a JS function to be invoked when the button is clicked i need pass the id on "openUpdateDialgo('id')"
),
'template'=>'{update}',
),
The htmlOptions cannot access $data object with column values - therefore suggested solution above cannot work. Getting row ID requires a little trick, here’s what worked for me:
add some hidden field named e.g. "rowid" into grid column:
define htmlOption for your button with the onclick attribute (dont use "click" option because if rendering page via ajax, it will attach event handler multiple times)