Json format - sAjaxDataProp
Json format - sAjaxDataProp

Can you help me.
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
Calling Ajax:
var table = $('#listRoles').dataTable({
"sAjaxSource": "${pageContext.request.contextPath}/api/roles",
"sAjaxDataProp": "",
"aoColumns": [
{ "mdata": "roleName"},
{ "mdata": "createdBy"},
{ "mdata": "dateTime"},
{ "mdata": "description"}
]
})
Result
{
"JSON": [
{
"id": 3,
"roleName": "ROLE_ADMIN",
"description": "Administrator",
"dateTime": 1581973182899,
"createdBy": "testuser"
},
{
"id": 5,
"roleName": "ROLE_DEV",
"description": "Role for all DEV",
"dateTime": 1582186318000,
"createdBy": "cicero.nogueira@ecrscorp.com"
},
{
"id": 1,
"roleName": "ROLE_EMPLOYEE",
"description": "Any employee",
"dateTime": 1581973182899,
"createdBy": "testuser"
}
]
}
ERROR : TypeError: d is undefined
Page loading.
What is wrong?
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
By default, DataTables expects the data to be within a
data
object, yours is inJSON
. Try settingajax.dataSrc
.Colin