I have a dynamic jQuery data table. For the final column, I have the option of deleting rows. In order for this to execute, I need to pass the itemId value to the function specified within the button onClick attribute.
This is how I have currently done it but no luck:
defaultContent: "<button class='btn btn-danger' onclick='StockSearchManagment.DeleteStock(" + data.itemId + ")'>Delete</button>"
This is my full JavaScript function:
GetInfo: function (tble) {
$(document).ready(function () {
$.ajax({
url: '/Home/GetList',
dataType: "json",
method: 'post',
success: function (data) {
tble.DataTable().destroy();
tble.DataTable({
data: data.html
,
"columns": [
{ data: "itemId" },
{ data: "name" },
{ data: "description" },
{
data: null,
defaultContent: "<button class='btn btn-danger' onclick='StockSearchManagment.DeleteStock(" + data.ItemId + ")'>Delete</button>"
}
]
});
},
error: function (err) {
alert(err);
}
});
});
}