ps_sach
(Ps Sach)
September 3, 2013, 4:46am
1
Hi All,
I need to remove js confirmation popup when I click on delete button in CGridView.
The confirmation is been handled in action and view in php.
The delete button does ajax call and invokes the action to get the response.
Everything works on the first page, when we go to the second page (CLinkPager) it gives the popup when clicked on the delete.
Please help me get this working!
Thanks in advance!
mdomba
(Maurizio Domba Cerin)
September 3, 2013, 7:38am
2
There is a Property in CButtonColumn as "deleteConfirmation",Make that Property to False then u will never get any Confirmation Message
Ankit_Modi
(Ankit Modi)
September 4, 2013, 4:34am
4
you can call the afterAjax method on second pagination
'afterAjaxUpdate'=>'function(id,options){
//code here
}',
ps_sach
(Ps Sach)
September 4, 2013, 7:58pm
5
Hi All,
As suggested by Maurizio and Dinesh, I have added deleteConfirmation => false in my CGridView widget and its not showing the js message.
Now after doing above changes it does not show the js confirmation message but it does not calls the action. When I click on the button it calls this js function -
jQuery('#user-groups-grid a.delete').live('click',function() {
var th=this;
var afterDelete=function(){};
$.fn.yiiGridView.update('user-groups-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$.fn.yiiGridView.update('user-groups-grid');
afterDelete(th,true,data);
},
error:function(XHR) {
return afterDelete(th,false,XHR);
}
});
return false;
});
And does nothing after this. So action is not getting called on 2nd page of the navigation.
I believe problem is related to ajax links. Now I will explain page layout and how it flows so that you can understand the problem.
I have menu ajax link which updates the content div and in content I have this delete ajax link which comes as ajax response rendered by action.
On first page everything works fine, but when we go to second page it gives js confirmation alerts.
Please help!
Ankit_Modi
(Ankit Modi)
September 5, 2013, 4:55am
6
you can put js code in function then after this function call on afterAjax method on grid view…
1)
<script>
function test(){
// your js live click function
}
</script>
2)
'afterAjaxUpdate'=>'function(id,options){
test();
}',
i hope it’s work
ps_sach
(Ps Sach)
September 6, 2013, 5:17am
7
Hello Maggie Q,
Thank you for the reply!
I am not able to understand where I should do the changes you suggested.
My menu link is ajax link -
echo CHtml::ajaxLink('Groups',
Yii::app()->createUrl('manage/groups/admin'),
array('success' => "function(data) {\$('#content').html(data);}"),
array('class' => 'left_border', 'href' => Yii::app()->createUrl('manage/groups/admin'), 'live'=>false)
);
The above page has zii.widgets.grid.CGridView and I have customized the CButtonColumn as follows -
class AjaxButtonColumn extends CButtonColumn {
protected function initDefaultButtons() {
$this->buttons = array(
'delete' => array(
'url' => 'Yii::app()->controller->createUrl("delete",array("id"=>$data->id))',
'label' => 'delete',
'options' => array(
'ajax' => array(
'type' => 'POST',
'url' => 'js:$(this).attr("href")',
'success' => 'js:function(data){$("#content").html(data);}',
),
'live' => false,
),
),
);
parent::initDefaultButtons();
}
}
?>
And above setup popup’s up js confirmation box on second page of pagination which I do not want at all.
Sometimes it gives multiple js popup, this could be because of multiple ajax handler registration!
Please guide to solve this problem!
Regards,