Revision #4 has been created by PinkBrainPlan on Mar 13, 2011, 2:16:39 PM with the memo:
finishing the code
« previous (#3)
Changes
Title
unchanged
CGridView and AjaxForm Connect
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
Ajax, Form, CGridView
Content
changed
[...]
'org_id',
array(
'class'=>'CButtonColumn',
'template'=>'{delete}',
'deleteButtonUrl'=>'Yii::app()->createUrl("//recipient/delete", array("id" => $data[\'rec_id\']))',
'buttons'=>array(
'update'=>array(
'url'=>'',
'options'=>array(
'ajax'=>array(
'type'=>'POST',
'url'=>"js:$(this).attr('href')",
//'update'=>"#mySubViewForm",
)
)
),
),
),
),
));[...]
?>
```
controller
To get it working, you should add the following code to your controller
```php
public function actionSubViewEdit()
{
if(isset($_POST['Recipient']['rec_id'])){
$model=$this->loadModel($_POST['Recipient']['rec_id']);
}else{
$model = new Recipient();
}
// Uncomment the following line if AJAX validation is needed
//$this->performAjaxValidation($model);
if(isset($_POST['Recipient']))
{
$model->attributes=$_POST['Recipient'];
$model->save();
}
}
public function actionSubViewLoad($id)
{
$criteria=new CDbCriteria(
array(
'condition'=>'rec_id = '.$id,
'with'=> array('org'),
));
$model=Recipient::model()->find($criteria);
$res = array(
'rec_id'=>$model->rec_id,
'org_id'=>$model->org_id,
'kom_id'=>$model->kom_id,
'nachname'=>$model->org->nachname,
'report_id'=>$model->report_id
);
echo CJSON::encode($res);
}
```
------------------
I hope this helps, if it can be done smarter, pls tell me!;-)