Cgridview Double Js Script

I had the main action




public function actionLoyalty()

    {

Yii::app()->clientScript->registerScript('load-grid_activity',

                '$("#activity").on("click",function() {

                    $("#grid-container").load("loyalty_ajax");

                });

                 $("#rewards").on("click",function() {

                    $("#grid-container").load("rewards_ajax");

                });

                 $("#reward_level").on("click",function() {

                    $("#grid-container").load("rewards_level_ajax");

                 })

');

$this->render('loyalty');

    }



and view. When i firstly download a page, using ajax i load to #grid-container CGridView

i had 3 links, and clicking different links i load different CGRIDVIEW using ajax.




<?php   Yii::app()->clientScript->registerScript('load-grid', '$("#grid-container").load("loyalty_ajax",{first:true});');

        echo CHtml::link('Activity', '#', array('id'=>'activity','class'=>'top_button'));

        echo CHtml::link('Rewards', '#', array('id'=>'rewards','class'=>'top_button'));

        echo CHtml::link('Reward Level', '#', array('id'=>'reward_level','class'=>'top_button'));

?>

                     <div id="grid-container"></div>



code of loading CGRIDVIEW, nothing special ,just at first time i load js files, at other times i don’t want to load them




if(!Yii::app()->request->isAjaxRequest) throw new CHttpException('Url should be requested via ajax only');

        Yii::app()->clientscript->scriptMap['jquery.js'] = false;

        if(!isset($_POST['first']))

        {

            Yii::app()->clientscript->scriptMap['jquery.ba-bbq.js'] = false;

            Yii::app()->clientscript->scriptMap['jquery.yiigridview.js'] = false;

            Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;

            Yii::app()->clientscript->scriptMap['jquery.yiiactiveform.js'] = false;

            Yii::app()->clientscript->scriptMap['jquery.multiselect.min.js'] = false;

        } else

        {

            Yii::app()->getClientScript()->registerCoreScript( 'jquery.ui' );

            Yii::app()->clientScript->registerCoreScript('yiiactiveform');

            $assets = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.multiselect') . '/assets');

            $cs = Yii::app()->getClientScript();

            $cs->registerScriptFile($assets . '/jquery.multiselect.min.js');

        }

        $itemsProvider=new CActiveDataProvider('Loyalty', array(

        'sort'=>array(

            'attributes'=>array(

                'action',

                'points',

            ),

        ),

        'pagination'=>array(

            'pageSize'=>20,

        ),

        ));

        $this->renderPartial('loyalty-grid', array('itemsProvider'=>$itemsProvider),false,true);



My Problem is that when i clicked second or third time to a link for example #rewards, i get the same event double ,then tripple and soo on for CButtonColumn

For example i clicked 3 time for link #rewards, and after i click button to delete 1 row, and i will receive 3 times confirmation window.

Hi ,

you want to create the random id for each link…


echo CHtml::link('Activity', '#', array('id'=>'activity_<?php echo rand(0,999999);?>','class'=>'top_button'));

i hope it’s works…