i have a problem with this project.
I\'m trying to create a crud menu, when hitting the Edit button the row\'s data will be transferred to a bootstrap modal and from the
Got it...
$('#example tbody').on('click', '.edit_btn', function () {
var data_row = table.row( $(this).parents('tr') ).data(); // here is the change
$("#myModal").modal('show');
$('#myModal').on('shown.bs.modal', function() {
$('#name').val(data_row.id);
$('#type').val(data_row.type);
$('#camp').html(data_row.campaign);
});
});
I would use a delegated event handler tbody .edit_btn
and grab the row through closest('tr')
:
$('#example').on('click', 'tbody .edit_btn', function () {
var data_row = table.row($(this).closest('tr')).data();
...
})
forked plunkr -> https://plnkr.co/edit/58vkkp3M6d68uuMknXus?p=preview