Yii Framework Forum: Ajax Request On Clicking Custom Button In Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Request On Clicking Custom Button In Cgridview Rate Topic: -----

#1 User is offline   vv2 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 17-January 14

Posted 17 January 2014 - 06:01 PM

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' => 'my-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'username',
'firstName',
'lastName',
'role',
array(
'header' => '',
'class' => 'CButtonColumn',
'template'=>'{status}',
'buttons'=>array
(
'status' => array
(

'click'=>"function(){
$.fn.yiiGridView.update('my-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$('#AjFlash').html(data).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');

$.fn.yiiGridView.update('my-grid');
}
})
return false;
}
",
'url'=>'Yii::app()->controller->createUrl("status",array("id"=>$data->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)
{

$model=member::model()->findByPk($id);
$model->firstName='Test2';
$model->save();



if(!isset($_GET['ajax']))
$this->redirect(Yii::app()->request->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
0

#2 User is offline   kaquilala 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-March 13

Posted 17 January 2014 - 08:00 PM

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

#3 User is offline   vv2 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 17-January 14

Posted 17 January 2014 - 10:31 PM

View Postkaquilala, on 17 January 2014 - 08:00 PM, said:

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 ..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users