My datatable is returning 982 blank rows and I'm really lost as to why! I also get this error message:
"Requested unknown parameter 'Key' for row 0, column 0."
I've looked in the console and this is the data that my datatable is getting from ajax:
{ "data": [ {"Summary":"Create lists of useful fields", "Created":"11/06/2020 13:03:36", "Updated":"18/01/2021 07:48:56", "Status":"Done", "Key":"PGT-2766", "Assignee":"Jane Doe", "Priority":"Lowest", "reporter":"Dave" },{"Summary":"test", "Created":"13/01/2021 14:30:04", "Updated":"13/01/2021 14:30:06", "Status":"To Do", "Key":"PGT-4622", "Assignee":"admin_user", "Priority":"Low", "reporter":"Dave" },{"Summary":"Review Rolling Programme queues/filters", "Created":"15/02/2021 14:32:21", "Updated":"08/03/2021 08:08:12", "Status":"In Progress", "Key":"PGT-5185", "Assignee":"Jane Doe", "Priority":"High", "reporter":"Dave" },{"Summary":"External LUSI Change Request Form: Bob - 19/1/2021", "Created":"19/01/2021 15:32:02", "Updated":"03/06/2021 08:59:17", "Status":"To Do", "Key":"PGT-4711", "Assignee":"admin_user", "Priority":"Low", "reporter":"Dave" } ] }
And this is my datatable:
var table = $('#example').DataTable({
ajax: {
url: pageUrl,
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: "json",
dataSrc: function (data) {
console.log(data.d);
return (data.d);
}
},
"pageLength": 50,
fixedHeader: true,
responsive: true,
"columns": [
{ "data": "Key" },
{ "data": "Summary" },
{ "data": "Created" },
{ "data": "Updated" },
{ "data": "Status" },
{ "data": "Priority" },
{ "data": "reporter" },
{ "data": "Assignee" }
],
autoWidth: false,
"columnDefs": [
{ "width": "50%", "targets": 0 },
{ "width": "5%", "targets": 1 },
{ "width": "5%", "targets": 2 },
{ "width": "5%", "targets": 3 },
{ "width": "5%", "targets": 4 },
{ "width": "5%", "targets": 5 }
],
"order": [[1, 'asc']],
"success": fnsuccesscallback,
"error": fnerrorcallback
});
function fnsuccesscallback(data) {
alert(data.d);
}
function fnerrorcallback(result) {
alert(result.statusText);
}
Really hoping someone can help as I'm really stuck!!!
Keyattribute which is your first column{ "data": "Key" }.dataSrcoption - it is not needed, if the JSON you show in your question is really the JSON being returned from your URL. However, your code as shown in the question does not run - thatdinconsole.log(data.d);is undefined and therefore will throw an error. So there is a mismatch between the behavior you describe and the code you provide.Keyas the first attribute in each JSON object - the order does not matter.)