Ajax Problem


Yii::app()->clientScript->registerScript('subdeletejs', "

$('.sdelete').click(function(){

alert('hai');

});


");

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

.....

....

'columns'=>array(

       name,

      array(

	 'class'=>'CButtonColumn',

         'template'=>'{view}{update}{deletethis}',

         'buttons'=>array(

               'deletethis'=>array(

                    'imageUrl'=>Yii::app()->baseUrl.'/images/delete.png',

                    'options'=>array('class'=>'sdelete'),

                ),

            ),

	  ),

),

)); ?>



This is sample code of my work format.

This code was working fine, When page load. When i use ajax update for gridview, it is not work. No error No output.

What i do ?


'columns'=>array(

       name,

should be:


'columns'=>array(

       'name',

When you reload elements with ajax event binding get removed. You have to add that js code to after update event of gridview that it runs after content has been updated and assigns event bindings to the new loaded elements.

I gave only sample format of my code. Everything working fine on page load. But registerScript not work on cgridview ajax page navigation

Have you read my post, mbala?

Thanks CIBI. I got solution




Yii::app()->clientScript->registerScript('subdeletejs', "

$('.sdelete').click(function(){

alert('hai');

});


");

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

.....

....

'columns'=>array(

       name,

      array(

         'class'=>'CButtonColumn',

         'template'=>'{view}{update}{deletethis}',

         'buttons'=>array(

               'deletethis'=>array(

                    'imageUrl'=>Yii::app()->baseUrl.'/images/delete.png',

                    'options'=>array('class'=>'sdelete'),

                ),

            ),

          ),

),

'afterAjaxUpdate'=>'function() {

  alert("Thank You");

}

)); ?>



It is working fine after every update of cgridview