CGridView and AJAX

Hi there,

I have a CGridView with AJAX mode enabled. One of the columns is a check-box that performs an AJAX request, archiving\getting an article out of the archive.

I should have thought of it beforehand, but when a user goes to the second page, sorts or searches items, "data" => "event=" . $data->event_id will stay the same for a row whatsoever, meaning it will always send requests as though a user were working with the unchanged data.

I will be really grateful if anyone can give me a hint on this one.


 array(

                    'name' => 'is_archived',

                    'filter'=>'',    

                    'header'=>'Arhive',

                    'type' => 'raw',

                    'value' => 'CHtml::checkBox("archive_event", 

                    $data->is_archived,

                    array(

                        "return" => true,

                        "ajax" => array(

                            "type" => "POST",

                            "url" => Yii::app()->createUrl("admin/event/archive"),                          

                            "data" =>  "event=" . $data->event_id,

                            "success" => "function(data){                                     

                                    $(\"#Notification\").jnotifyAddMessage({

                                        text: data,

                                        permanent: false

                                    });

                            }

                            ",

                        )                           

                    )                     

                 )',                                    ),

ok, there seem to be no standard way to stop yii from putting quotes around data when scripts are being created, meaning you can’t use jQuery selectors in “data” and it is probably better to avoid using CHtml’s ajax() requests when CGridView is in AJAX mode and just write it manually. It kinda sucks that I always run into those numerous little things that make it simpler to do everything the old way.

Try adding "js:" (without quotes), it helps with quotes when writing JS scripts.