Ccheckboxcolumn And Ajax

Hello,

I would like to run Ajax on a CCheckBoxColumn.

AnyBody know how to do it ?

I try with a classic column, but I didn’t reach the solution.

first approach




      array(

            'class' => 'CCheckBoxColumn',

            'id' => 'ckAm',

            'header' => 'pres am',

            'headerTemplate'  => 'pres PM',

            'visible' => '$data->fkPlanning->fk_code_am_pm == Yii::app()->params["codeAm"] || $data->fkPlanning->fk_code_am_pm == Yii::app()->params["codeAmPm"] ? true:falase',

            'selectableRows' => 2,

            'htmlOptions' =>array('ajax' => array(

                'type' => 'POST',

                'dataType' => 'json',

                 'url' => Controller::createUrl('/dfcMesureFormHasPlanning/majPresence'),

                'data' => array('codeAmPm' => Yii::app()->params['codePm']))),

        ), // 'fkPlanningId' => '$data->fk_planning_id','fkMesureForm' => '$data->fk_mesure_form_id',



second approach




 array(

        'name'=>'ckAm',

        'type'=>'raw',

        'value'=>'CHtml::checkbox("$data->is_present_am", "$data->is_present_am", array("htmlOptions" =>array("ajax" => array(

                "type" => "POST",

                "dataType" => "json",

                "url" => Controller::createUrl("/dfcMesureFormHasPlanning/majPresence"),

                "data" => array("codeAmPm" => Yii::app()->params[\'codePm\']))),

            

        ));',

),



thanks

Nath

I think you should handle checkbox click separately, something like:




// Column config

array(

    'class'=>'zii.widgets.grid.CCheckBoxColumn',

    'checked'=>//condition...

    'checkBoxHtmlOptions'=>array(

        'class'=>'my-checkbox',

    ),

),


// Register JS somewhere...

$checkBoxUrl = $this->createUrl('/dfcMesureFormHasPlanning/majPresence');

$js = <<<JS

$('.my-checkbox').change(function() {

$.get('$checkBoxUrl', {...params...});

});

JS;

Yii::app()->clientScript->registerScript('checkbox', $js);



Sending params is a bit tricky. You can try to use rowHtmlOptionsExpression to set row data.

Hope this helps…

Hi there

Yii was developed to help you, but you can always write you javascript in raw javascript it relatively easy to accomplish with jquery


$('.my-checkbox').change(function() {

  $.get('/dfcMesureFormHasPlanning/majPresence', {'param1'=>'value'});

});

you can actually do lot more raw javascript gives you lot more flexibility