我在项目中使用yii2mod/yii2-sweet-alert,在基本和高级主题上都使用它,我很喜欢它。
问题: 如何更改网格默认确认对话框,以便使用Sweet-alert使其外观更好?
我已经尝试修改删除按钮的模板,因为如果您想要更改消息,可以执行以下操作:
[
'class' => ActionColumn::className(),
'template' => '{update}{delete}',
'buttons' => [
'delete' => function($url, $model){
return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], [
'class' => '',
'data' => [
'confirm' => 'Are you absolutely sure ? You will lose all the information about this user with this action.',
'method' => 'post',
],
]);
}
]
]
但是我一直没有成功将确认消息从javascript更改为sweet alert。
我正在尝试第二种选择,使用Krajee/ Grid和actionColumn使其工作,但仍无法使其工作。 «这是我正在进行的第二个选择,以实现此目标»。
[
'class' => 'kartik\grid\ActionColumn',
'viewOptions' => ['hidden' => true],
'updateOptions' => ['title' => 'Edit events', 'data-toggle' => '??'],
'deleteOptions' => ['title' => 'delete your event', 'data-toggle' => 'I am Lost here'],
],
请问如何改变这个行为?
如何解决问题的更多信息 - 感谢 @muhammad-omer-aslam
create a js file on your public folder, in my case
/backend/web/js/confirmSwal.js
and add the provided code:Add these lines
yii.confirm = function (message, okCallback, cancelCallback) { swal({ title: message, type: 'warning', showCancelButton: true, closeOnConfirm: true, allowOutsideClick: true }, okCallback); };
Add this to your AppAssets on
/backend/assets/AppAssets.php
public $js = [ '/js/confirmSwal.js', ];
And that's it it works beautiful.
再次感谢穆罕默德。