I'd like to make a confirm deletion using modal over a modal that contain table because with confirm()
doesn't work. The table itself is exist on modal. Here's some pictures of my table
When I click delete button, it'll show pop-up confirm deletion.
But the delete button in confirm deletion pop-up doesn't work. Here's my table code:
<table class="table table-striped table-bordered table-hover table-condensed table-checkable order-column" id="lapkinerja-grafik-admin">
<thead>
<tr>
<th width="5%">No.</th>
<th width="60%">Nama File</th>
<th width="25%">Bulan</th>
<th width="10%">Action</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach($grafikAdmin as $key => $row) {
$filename = $row['NAMA_FILE'];?>
<tr class="isi-row">
<td><?php echo $no++;?></td>
<td>
<a href="<?php echo base_url();?>sms/download_grafik/index?fileName=<?php echo $filename;?>"><?php echo $filename;?></a>
</td>
<td><?php echo $row['BULAN'];?></td>
<td>
<button id="delete" class="delete-button" value="<?php echo $row['ID_FILE'];?>" data-value="<?php echo $filename;?>" type="button" data-toggle="modal" data-target="#delete-modal">
Delete
</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Confirm deletion pop-up code:
<div class="modal fade" id="delete-modal" role="dialog">
<div class="modal-dialog modal-sm">
<!--modal delete content start-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<h5>Are you sure to delete this?</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button id="del-alert" class="btn btn-danger btn-del">Delete</button>
</div>
</div>
<!--modal delete content end-->
</div>
</div>
And here's my javascript code:
$('#lapkinerja-grafik-admin').on('click', '#delete',function(e) {
e.preventDefault();
var table = $('#lapkinerja-grafik-admin').DataTable({
"retrieve": true,
"columns": [
null,
null,
null,
{
"sortable": false
}
]
});
$('#delete-modal').on('show.bs.modal', function() {
$('.btn-del').click(function() {
console.log($(this).parent());
table.row($(this).parents('.isi-row')).remove().draw(false);
});
});
});