Yii Framework Forum: Gridview, Cbuttoncolumn And Ajax - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Gridview, Cbuttoncolumn And Ajax Rate Topic: -----

#1 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 07 December 2012 - 08:15 AM

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
0

#2 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 07 December 2012 - 09:11 AM

Hi Nath,

In your use case ,I will have done something like

'update' => array(
                     //'options' => array(
                     //   'onclick' => 'js: $("#formUpdate").show();return false;;',
                     //),
                      'ajax' => array(
                    'type' => 'POST',
           //use 'update' feature of ajax request
                    'update'=>'#formUpdate',      
                    'ajaxUrl' => Controller :: createUrl('/TRapportsActivites/MajFormUpdate'),
                    'dataType' => 'json',
                    'data' => array('id' =>'js:this.value'),
          // the form will be updated via "renderPartial" from controller action
                    /*'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);    

                                        }',*/
                    )


elsewhere in your view:

<div id="formUpdate"></div>


and in your controller:

public function actionMajFormUpdate()
        {
        if (Yii::app()->request->isAjaxRequest) {
            
            $id = $_POST['id']; 
            print_r($id);
            $model=$this->loadModel($id);
            $this->renderPartial('myUpdateForm',array('model'=>$model),false,true);
        }
    }


not tested, but it should work
Hey Ho !
Let's go !
0

#3 User is offline   nath-0 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 12-October 12
  • Location:switzerland

Posted 10 December 2012 - 09:53 AM

Thank you for you answer.

At the End, I use JUIDialog, but I'am sure that will be usefull for me other time ;-)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users