Hello,
I am trying to use Ajax with CButtonColumn :
View Admin
array(
'class'=>'QButtonColumn',
'template' => '{update}{delete}',
'deleteButtonUrl'=>'Yii::app()->createUrl("/TRapportsActivites/delete", array("id" => $data->rapport_activite_id))',
'updateButtonUrl'=>'Yii::app()->createUrl("/TRapportsActivites/update", array("id" => $data->rapport_activite_id))',
'buttons' => array(
'update' => array(
'options' => array(
'onclick' => 'js: $("#formUpdate").show();return false;;',
),
'ajax' => array(
'type' => 'POST',
'ajaxUrl' => Controller :: createUrl('/TRapportsActivites/MajFormUpdate'),
'dataType' => 'json',
'data' => array('id' =>'js:this.value'),
'success' => 'function(data) {
$("#' . CHtml::activeId($model, 'date') . '").val(data.date);
$("#' . CHtml::activeId($model, 'heure') . '").val(data.heure);
$("#' . CHtml::activeId($model, 'libelle') . '").val(data.libelle);
$("#' . CHtml::activeId($model, 'facture') . '").val(data.facture);
}',
)
)
TRapportsActivitesController
public function actionMajFormUpdate()
{
if (Yii::app()->request->isAjaxRequest) {
$id = $_POST['id'];
print_r($id);
$model=$this->loadModel($id);
echo CJSON::encode(array(
'date' => $model->date,
'heure' => $model->heure,
'libelle' => $model->libelle_public,
'facture' => $model->facture,
));
}
}
But Ajax don’t run actionMajFormUpdate.
In fact I would like to update my form in the same view as the viwe where is my gridview.
So, when I click button update, I display the form update with javascript, but the form is not populate with values.
I son’t think I choose the good way for do this, so If you have advice, let me know !
Nath who is sorry for his bad english