I have a custom ActionColumn
on GridView
and trying to call yii.confirm function using data-confirm for delete action but the dialog not shown.
[
'format'=>'html',
'content'=>function($data) {
$btn = ButtonDropdown::widget([
'label' => 'Action',
'options' => ['class'=>'btn btn-sm btn-primary dropdown-toggle', 'type'=>'button'],
'dropdown' => [
'options' => ['class'=>'dropdown-menu action', 'role'=>'menu'],
'items' => [
'<li><a href="'.Url::to(['details','id'=>$data->id]) .'"><i class="fa fa-pencil"></i> Details</a></li>',
'<li><a href="'. Url::to(['edit', 'id' => $data->id]) .'"><i class="fa fa-eye"></i> Edit</a></li>',
'<li role="presentation" class="divider"></li>',
'<li><a data-method="post" data-confirm="Are you sure ?" href="'.Url::to(['delete', 'id' => $data->id]).'"><i class="fa fa-trash"></i> Delete</a></li>',
],
],
]);
return $btn;
},
],
But when I'm trying to add link without dropdown it works
[
'format'=>'html',//raw, html
'content'=>function($data) {
$btn ='<a data-method="post" data-confirm="Are you sure ?" href="'.Url::to(['delete', 'id' => $data->id]).'"><i class="fa fa-trash"></i> Delete</a>';
return $btn;
},
],
You can add a link like this
<?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
I should use linkOtions form Items
[
'format'=>'html',
'content'=>function($data) {
$btn = ButtonDropdown::widget([
'label' => 'Action',
'options' => ['class'=>'btn btn-sm btn-primary dropdown-toggle', 'type'=>'button'],
'dropdown' => [
'options' => ['class'=>'dropdown-menu action', 'role'=>'menu'],
'items' => [
['label' => 'Details', 'url' => ['details','id'=>$data->id],
'linkOptions' => ['class'=>'fa fa-pencil'],],
['label' => 'Edit', 'url' => ['edit','id'=>$data->id],
'linkOptions' => ['class'=>'fa fa-eye'],],
['label' => '<span role="presentation" class="divider"></span>'],
['label' => 'Delete', 'url' => ['delete','id'=>$data->id],
'linkOptions' => ['class'=>'fa fa-trash' , 'data' => [
'confirm' => 'Are you sure ?',
'method' => 'post',
]],],
],
],
]);
return $btn;
},
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With