Json format - sAjaxDataProp

Json format - sAjaxDataProp

cicjrcicjr Posts: 7Questions: 2Answers: 0
edited February 2020 in Free community support

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.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    By default, DataTables expects the data to be within a data object, yours is in JSON. Try setting ajax.dataSrc.

    Colin

This discussion has been closed.