Can someone help me figure out why I am getting a SyntaxError when trying to trigger a function in a datatable cell using an onclick event on a button? The button is successfully created, but the error occurs when clicking it.
The problem seems to lie within the render switch case 0. The exact error message I'm receiving is:
SyntaxError: expected expression, got '}'
Here is the code I am using:
function LoadHistory(phone) {
$.ajax({
url: '/api/TransferFunds/' + phone,
type: 'Get',
dataType: 'json',
contentType: "application/json; charset-utf-8",
success: function (data) {
datatableVariable = $('#table').DataTable({
data: data,
autoWidth: true,
responsive: false,
paging: true,
lengthChange: false,
searching: false,
ordering: false,
info: true,
columns: [
{ 'data': 'id' },
{ 'data': 'transType' },
{ 'data': 'network' },
{ 'data': 'phoneNumber' },
{ 'data': 'internalReference' },
{
'data': 'amount',
"render": function (value) {
return "GHS" + formatmoney(value);
}
},
{
'data': 'dateSent',
"render": function (value) {
return value;
}
},
{
'data': 'status',
"render": function (data, type, row, meta) {
var evt = row['internalReference'];
switch (data) {
case 0:
return '<button class="btn btn-default" onclick="return GetStatus("' + evt + '");">Pending </button>';
break;
case 1:
return '<button class="btn btn-success" >Successful</button>';
break;
case 2:
return '<div class="btn btn-warning">Rejected </div>';
break;
case 3:
return '<div class="btn btn-danger">Failed </div>';
break;
default:
break;
}
}
}
],
columnDefs: [
{ "visible": false, "targets": [0, 4] }
]
});
}
});
}