Cgridview, Chtml::ajaxlink And Cache Mechanism Issue After Filter Applied

Hello Yiiers,

I believe it is something about AjaxLink and the cache mechanism or ERememberFiltersBehavior usage but I am not sure. I have tried to find something related in the forum but no success.

I have coded a column with AjaxLink to show a CJuiDialog popup that shows more details about that column.

At the first renderization time, everything is Ok. The AjaxLink shows the current description (1st param) and its associated link (2nd param) runs fine, passing the right column value ($data->numprotocolo) to controller/action.

But whenever I change some filter in that grid, bringing new results, AjaxLink/CGridView insists in passing the value from the old row (before applying some filter) although the new description is shown correctly.

Pressing browser refresh key helps to get the correct value.

Any directions? Please help!

(Using Yii 1.1.13)

In the view:




$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'mygrid',

        'dataProvider'=>$model->search(),

	'filter'=>$model,

         :::::::

	'columns'=>array(

            :::::::

	   array(

              'name'=>'numprotocolo',

              'type'=>'raw',

	      'value'=>'CHtml::ajaxLink(

                        $data->numprotocolo,

			array("contrato/recuperaProtocolo","numprotocolo"=>$data->numprotocolo),

			array(

                          "success"=> "

                             function(data){

                               $(\'#popupContent\').html(data);

                               $(\'#showProtocolo\').dialog(\'open\');

                               return false;

                             } ",

                          ))',

          ::::::

        ),

     ::::::

));



In the controller:




public function actionRecuperaProtocolo($numprotocolo)

{

	echo Contrato::model()->recuperaProtocolo($numprotocolo);

	Yii::app()->end();

}



I’ve also tried to use uniqid() and change how to pass the parameter data to the controller:




        array(

            'name'=>'numprotocolo',

            'type'=>'raw',

            'value'=>'CHtml::ajaxLink(

                    $data->numprotocolo,

                    array("contrato/recuperaProtocolo"),

                    array(

                        "data"=>array("numprotocolo"=>$data->numprotocolo),

                        "success"=> "

                             function(data){

                               $(\'#popupContent\').html(data);

                               $(\'#showProtocolo\').dialog(\'open\');

                               return false;

                             } ",

                    ),                   

                    array(

                        "id" => "id-".uniqid()

                    )

                )',

        ),



and inspecting the generated page code, I see:




jQuery('#mygrid').yiiGridView({'ajaxUpdate':['mygrid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'enableHistory':false,'updateSelector':'{page}, {sort}','pageVar':'Contrato_page'});

$('body').on('click','#id-524b3dfddb6aa',function(){jQuery.ajax({'data':{'numprotocolo':'402.381/2011'},'success':

                             function(data){

                               $('#popupContent').html(data);

                               $('#showProtocolo').dialog('open');

                               return false;

                             } ,'url':'/myapp/index.php?r=contrato/recuperaProtocolo','cache':false});return false;});

$('body').on('click','#id-524b3dfddbc69',function(){jQuery.ajax({'data':{'numprotocolo':'266.183/2011'},'success':

                             function(data){

                               $('#popupContent').html(data);

                               $('#showProtocolo').dialog('open');

                               return false;

                             } ,'url':'/myapp/index.php?r=contrato/recuperaProtocolo','cache':false});return false;});

$('body').on('click','#id-524b3dfddbf8f',function(){jQuery.ajax({'data':{'numprotocolo':'309.688/2009'},'success':

                             function(data){

                               $('#popupContent').html(data);

                               $('#showProtocolo').dialog('open');

                               return false;

                             } ,'url':'/myapp/index.php?r=contrato/recuperaProtocolo','cache':false});return false;});

});




The key issue appears to be the CGridView is not rebuilding the click events on ajax selectors $(‘body’) (one for each new row) as a new filter is given.

Any advice?

Hi,

Have you try the update grid view after ajaxlink success


$.fn.yiiGridView.update("<id of CGridView>");

Thanks Ankit Modi for your reply.

Iv sent a bad diagnostic as I didnt refresh the inspected code! I apology for that. :(

But this post (by Haensel) solved my problem:

http://www.yiiframework.com/forum/index.php/topic/31852-ajaxlink-does-not-work/

So, in my controller I put that check changing it to:




    public function actionRecuperaProtocolo()

    {

        if(Yii::app()->request->isAjaxRequest)

            Yii::app()->clientScript->scriptMap=array("jquery.js"=>false, 'duplicatedScrip.js'=>false);

        echo $_GET['numprotocolo'];

        // echo Contrato::model()->recuperaProtocolo($_GET['numprotocolo']);

        Yii::app()->end();

    }



and I am Yiihappy again! :)

Thank you both.

hello Aluizio,

what did really you do?

I have same problem with you, I use ajaxLink in CGridView but after filtering the data, the ajax link didn’t update the link but still use the old link.

thank you in advance