How can I perform a JavaScript action if the ok button has been pressed in the deleteConfirmation message in CGridview when item needs to be deleted

I have a scenario when an item is deleted in CGridview and JavaScript action needs to be performed, if the confirmation message appears and a user clicks on Cancel nothing should happen, if he clicks on OK a javascript action should happen. My problem at the moment is, I can’t get the action to be performed specifically when the action has been completed. How do I overwrite this jquery ajax function within CGridview from




jQuery('#user-group-grid a.delete').live('click',function() {

	if(!confirm('Are you sure you want to delete this item?')) return false;

	$.fn.yiiGridView.update('user-group-grid', {

		type:'POST',

		url:$(this).attr('href'),

		success:function() {

			$.fn.yiiGridView.update('user-group-grid');

		}

	});

	return false;

});

to this


jQuery('#user-group-grid a.delete').live('click',function() {

	if(!confirm('Are you sure you want to delete this item?')) return false;

	$.fn.yiiGridView.update('user-group-grid', {

		type:'POST',

		url:$(this).attr('href'),

		success:function() {

                        $("#successAdd").hide();

                        var id = $(this).parent().parent().children(\':first-child\').text();

                        $("#userGroup_groups option[value='"+id+"']").remove();

			$.fn.yiiGridView.update('user-group-grid');

		}

	});

My CGridview code


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

                            'id'=>'user-group-grid',

                            'dataProvider'=>$model->getAllGroups(),

                            'enablePagination'=>true,

                            'pager' => array('pageSize'=>2),

                            'columns'=>array(

                                    'id'=>array(

                                        'name'=>'id',

                                        'value'=>$model->id,

                                        'htmlOptions'=>array('style'=>'display:none'),

                                        'headerHtmlOptions'=>array('style'=>'display:none')

                                     ),

                                    'name',

                                    'description',

                                    'createDate',

                                    array(

                                            'class'=>'CButtonColumn',

                                            'template'=>'{update} {delete}',

                                            'buttons' => array(

                                                'delete'=>array(

                                                    'options'=>array(

                                                        'onclick'=>'js:$("#successAdd").hide();var id = $(this).parent().parent().children(\':first-child\').text();$("#userGroup_groups option[value=\'"+id+"\']").remove();',

                                                        ),

                                                ),

                                                'update'=>array(

                                                    'options'=>array(

                                                        'onclick'=>'js:$("#updateButton").show();

                                                        $("#userGroup_name").val($(this).parent().parent().children(\':nth-child(2)\').text());

                                                        $("#userGroup_description").val($(this).parent().parent().children(\':nth-child(3)\').text());

                                                        $("#row_id").val($(this).parent().parent().children(\':first-child\').text());

                                                        $(".errorSummary").hide();

                                                        $("#addButton").hide();

                                                        $("#successAdd").hide();

                                                        return false;'

                                                    )

                                                ),

                                            )

                                    ),

                            ),

                         ));

return false;

});

I’ve read this can be changed by modifying the delete buttons template, but how do I modify the template

The default delete button has it’s code hard coded… so you cannot change that…

So the solution as you read it is to not use the default one and to make a custom "delete" button

Here is a good wiki article on customizing the CButtonColumn - http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview

Thanks, I had a look at the tutorial and it worked for me, thank you