I am using datatables, in one column I have a button which is used for deletion. Clicking this button needs to show a modal, which then shows YES/NO to delete the row.
I managed to get the modal working but I cannot get the javascript to fetch my id's at all. It does not register the click event.
This is the code I have (i omitted the obvious part of the code, eg the table):
echo "<td>";
$deletetitle = lang('general_delete');
echo "<button class=\"btn btn-secondary rowBtnDelete\" data-toggle=\"modal\" data-target=\"#deletemodal\" data-vacid=\"$vac->vacancy_id\" data-userid=\"$this->auth_user_id\">$deletetitle</button>";
echo "</td>";
Modal code:
<!-- Modal dialog for the deletion confirmation -->
<?php
$delAction = 'dashboard/deleteVacancy';
?>
<div id="deletemodal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="title-delete" aria-hidden="true">
<div class="modal-dialog" role="document">
<form class="modal-content" action="<?=site_url( $delAction, $link_protocol )?>" method="post" data-class="validation">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span class="fa fa-times" aria-hidden="true"></span>
</button>
<h4 class="modal-title" id="title-duplicate">verwijderen?</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<?php echo form_submit('deletebtn', lang("general_yes"), "class='btn btn-secondary'"); ?>
<a id="delcancelmodal" class="btn btn-secondary" data-dismiss="modal"><?=lang("general_no")?></a>
</div>
</form>
</div>
</div>
Now when I am doing the following in javascript nothing happens (i expect the alert to pop up??):
$(document).ready(function () {
$('button.rowBtnDelete').on('click', function (e) {
e.preventDefault();
//var id = $(this).closest('tr').data('id');
//$('#deletemodal').data('id', id).modal('show');
alert("pls");
});
});
EDIT: the datatable config code looks like this: //DataTables on "my vacancies" page for organisations
var table = $('#table_id').DataTable({
"language": {
"decimal": "",
"emptyTable": "Geen data gevonden in tabel",
"info": "Toon _START_ tot _END_ van de _TOTAL_ activiteiten",
"infoEmpty": "Toon 0 tot 0 van de 0 activiteiten",
"infoFiltered": "(gefilterd van _MAX_ totale activiteiten)",
"infoPostFix": "",
"thousands": ",",
"lengthMenu": "Toon _MENU_ activiteiten",
"loadingRecords": "Loading...",
"processing": "Processing...",
"search": "Zoeken:",
"zeroRecords": "Geen resultaten gevonden voor je zoekopdracht",
"paginate": {
"first": "Eerste",
"last": "Laatste",
"next": "Volgende",
"previous": "Vorige"
},
"aria": {
"sortAscending": ": klik om de kolom oplopend te sorteren",
"sortDescending": ": klik om de kolom aflopend te sorteren"
}
},
"order": [[ 1, "desc" ]],
dom: 'Bfrtip',
buttons: [
{
extend: 'copy',
orientation: 'landscape',
pageSize: 'LEGAL',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
}
},
{
extend: 'excel',
orientation: 'landscape',
pageSize: 'LEGAL',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
}
},
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'LEGAL',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
}
}
],
"pagingType": "full_numbers",
drawCallback: function() {
$('button.rowBtnDelete').on('click', function (e) {
//e.preventDefault();
alert("pls");
// Get data like so
//$(this).data('vacid');
});
}
});
$(document).ready()block in a script tag at the bottom of the page?