Ajax Request On Clicking Custom Button In Cgridview

Hi,

I was trying to create a custom button which will modify database. I was using cgridview and created custom button. However, when I click the button, the database does get modified but the request is a normal post request and not an ajax request…

here’s what I;m doing

View

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

								'id' =&gt; 'my-grid',


						               	'dataProvider'=&gt;&#036;dataProvider,


								'columns'=&gt;array(


									'id',									


									'username',


									'firstName',


									'lastName',


									'role',


									array(


					'header' =&gt; '',


					'class' =&gt; 'CButtonColumn',


					'template'=&gt;'{status}',

‘buttons’=>array

(


    'status' =&gt; array


    (


        


                   'click'=&gt;&quot;function(){


                                &#036;.fn.yiiGridView.update('my-grid', {


                                    type:'POST',


                                    url:&#036;(this).attr('href'),


                                    success:function(data) {


                                          &#036;('#AjFlash').html(data).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');





                                          &#036;.fn.yiiGridView.update('my-grid');


                                    }


                                })


                                return false;


                          }


                 &quot;,


        'url'=&gt;'Yii::app()-&gt;controller-&gt;createUrl(&quot;status&quot;,array(&quot;id&quot;=&gt;&#036;data-&gt;id))',


    )) ,


															


					),),

)); ?>

<div id=‘AjFlash’ class=“flash-success” style=“display:none”>Hello</div>

On clicking the button, the database get’s mofified and my grid gets updated with the value but the flash message is not displayed

here is my controller

public function actionStatus($id)

{


     


  &#036;model=member::model()-&gt;findByPk(&#036;id);


  &#036;model-&gt;firstName='Test2';


      &#036;model-&gt;save();


     


         		


  		           


if(&#33;isset(&#036;_GET['ajax']))


       &#036;this-&gt;redirect(Yii::app()-&gt;request-&gt;urlReferrer); 





	            


	


}

If I do not check for isset($_GET[‘ajax’]), I’m not returned back to my view which means that this request is not ajax right? and if it is why is my flash message not displaying?

Any help would be appreciated…

Rgds

vv

If you want to display a message from your controller you should echo it from your action.

Yes I have tried that as well … even if I’m not echoing anything. shouldn’t it just display the ajflash div …