Yii Framework Forum: Click Event Not Working In Cgridview - Yii Framework Forum

Jump to content

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

Click Event Not Working In Cgridview Rate Topic: -----

#1 User is offline   Vishal Yadav 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-July 13

Posted 11 July 2013 - 03:51 AM

Hello All,

Please help me to sort out the issue which i am facing.
I am using cGridView and want to apply ajax to change the status of each record(active/inactive)

In action button I want to give ajax link to update the status(0 OR 1)

Problem : Click event is not showing in HTML view of <a> tag.

Here is my code :

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

'columns'=>array(
array(
'id'=>'autoId',
'class'=>'CCheckBoxColumn',
'selectableRows' => '50',
),

array(
'name'=>'name',
'value'=>'$data->name',
),

array( // display 'status' using an expression
'name'=>'status',
'value'=>'$data->status',
),

array( // display a column with "view", "update" and "delete" buttons
'class'=>'CButtonColumn',
'template'=>'{edit} {status}',

'buttons' =>array
(
'edit' => array
(
'label'=>'Edit',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/edit.png',
'url'=>'Yii::app()->createUrl("product/prodcatedit", array("id"=>$data->id))',
),

'status' => array
(
'label'=>'status',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/edit.png', // make sure you have an image

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

$.fn.yiiGridView.update('mygrid');
}
})
return false;
}",
'url'=>'Yii::app()->createUrl("product/categorystatus", array("id"=>$data->id))',

)


),

),

),
)); ?>


AND in view there is no click event :
<a class="status" href="/backend/product/categorystatus?id=1" title="status">
<img alt="status" src="/images/edit.png">
</a>

Please let me know in case of anything i am doing wrong.

Thanks,
Vishal
0

#2 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 11 July 2013 - 04:35 AM

View PostVishal Yadav, on 11 July 2013 - 03:51 AM, said:

Hello All,

Please help me to sort out the issue which i am facing.
I am using cGridView and want to apply ajax to change the status of each record(active/inactive)

In action button I want to give ajax link to update the status(0 OR 1)

Problem : Click event is not showing in HTML view of <a> tag.

Here is my code :

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

'columns'=>array(
array(
'id'=>'autoId',
'class'=>'CCheckBoxColumn',
'selectableRows' => '50',
),

array(
'name'=>'name',
'value'=>'$data->name',
),

array( // display 'status' using an expression
'name'=>'status',
'value'=>'$data->status',
),

array( // display a column with "view", "update" and "delete" buttons
'class'=>'CButtonColumn',
'template'=>'{edit} {status}',

'buttons' =>array
(
'edit' => array
(
'label'=>'Edit',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/edit.png',
'url'=>'Yii::app()->createUrl("product/prodcatedit", array("id"=>$data->id))',
),

'status' => array
(
'label'=>'status',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/edit.png', // make sure you have an image

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

$.fn.yiiGridView.update('mygrid');
}
})
return false;
}",
'url'=>'Yii::app()->createUrl("product/categorystatus", array("id"=>$data->id))',

)


),

),

),
)); ?>


AND in view there is no click event :
<a class="status" href="/backend/product/categorystatus?id=1" title="status">
<img alt="status" src="/images/edit.png">
</a>

Please let me know in case of anything i am doing wrong.

Thanks,
Vishal



Please refer this URL
and check are you doing in correct way. also please use code block to put your code. So, easily it can understand. ;)

And also please check the function again which you have bind on click event. Is control is going into this or not.
CodeSutra
0

#3 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 866
  • Joined: 19-February 13
  • Location:India

Posted 11 July 2013 - 05:30 AM

Hi,

please see this link


www.yiiframework.com/forum/index.php/topic/42793-cgridview-delete-action/page__view__findpost__p__203223__fromsearch__1

it may be helpful
Thanks,
Ankit Modi
Skype : amodi06
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