Add alert confirmation on redefined ActionColumn

Hello,

I’m using GridView do display users in my web app and I’ve redefined the delete action like the following:





         [

                'class' => 'yii\grid\ActionColumn',

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

                'buttons' => [

                    'update' => function ($url, $model) {

                        return Html::a(

                            '<span class="glyphicon glyphicon-pencil"></span>',

                            $url ='index.php?r=user/admin/update&id='.$model->id, 

                            [

                                'title' => 'Download',

                                'data-pjax' => '0',

                            ]

                        );

                    },

                    'delete' => function ($url, $model) {

                        return Html::a(

                            '<span class="glyphicon glyphicon-trash"></span>',

                            $url ='index.php?r=user/admin/delete&id='.$model->id, 

                            [

                                'title' => 'Download',

                                'data-pjax' => '0',

                            ]

                        );

                    },

                ],

            ],           

                    

                    

                    

                    

    ],




Everything works fine except that, when I press the delete button, there are no more alert confirmation messages.

Since I can’t find the answer in the official documentation, how can I add an alert confirmation on the delete action?

Thank you

Ale

Hello,

try this,




],

    	'buttons'  => [

    	'delete' => function($url, $model) {

            	return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model['id']], [

                    	'title' => Yii::t('app', 'Delete'), 'data-confirm' => Yii::t('app', 'Are you sure you want to delete this Record?'),'data-method' => 'post']);

    	}

    	],



1 Like

It works fine!

Thank you very much!

Alessandro