I am using the jquery datatable with ajax call to fetch the data. I am trying to add the delete button so whenever the delete button is clicked I can get the ID of clicked row. But yet my code is just picking up the first ID of the row. Here is my code
<script type="text/javascript">
var table = $('#table1').DataTable( {
dom: "Bfrtip",
ajax: {
url : "http://localhost/cokeinventory/rest-api/api-search-stockin.php",
dataSrc: "doc",
},
columns: [
{ data: 'stock_id'},
{ data: 'item_name'},
{ data: 'unit' },
{ data: 'stockin_qty' },
{ data: 'barcode_number' },
{ data: 'barcode_label' },
{ data: 'balquantity' },
{
data: null,
className: "dt-center editor-delete",
orderable: false,
"mRender" : function ( data, type, row ) {
return '<button class="btn btn-success" id="deletebtn" value=' +data.stock_id +' >Delete <i class="fe fe-delete"></i></button>';
}
}
],
});
$("body").on("click", "#deletebtn", function(){
var val = $("#deletebtn").val();
alert(val);
});
});
</script>