JSON -> "No data available in table"

JSON -> "No data available in table"

paaypaay Posts: 3Questions: 1Answers: 0

Hey everyone,

I've checked all the examples and help in the forums, but unfortunately I could not get my issue resolved. Maybe someone here can help me, would really appreciate it.

The table is just empty, and it displays that "no data is available in the table".

I'm getting JSON from a txt file, I have validated the JSON that's in there with jsonlint.com.
I have also verified with Firebug, that I'm receiving the JSON data within the script.

My assumption is, that I'm missing a parameter within the datatable script - any idea?

  1. My JavaScript:
    $(document).ready(function() {

    $('#example').dataTable( {

    "sAjaxSource": "../protected/controller/data.txt",
    "sAjaxDataProp":"",
    
      "columns": [ {
                "mDataProp": "ID",
                "title": "ID"
            }, {
                "mDataProp": "Name",
                "title": "Name" 
            }, {
                "mDataProp": "Name_ext",
                "title": "External Name"
            }, {
                "mDataProp": "Mail",
                "title": "E-Mail"
            }, {
                "mDataProp": "BG_ID",
                "title": "BackID"
            }, {
                "mDataProp": "LLOG",
                "title": "Live-Log"
            }, {
                "mDataProp": "RHASH",
                "title": "Read-Hash"
            }, {
                "mDataProp": "USRN",
                "title": "User-RN"
            }, {
                "mDataProp": "USPW",
                "title": "User-PW"
            } ],
    

    } );

});

  1. My HTML:
  1. My JSON:
    {
    "users": [
    {
    "ID": "1",
    "Name": "Lorem",
    "Name_ext": "Ipsum",
    "Mail": "smo@localdmn",
    "BG_ID": "1",
    "LLOG": "ea rebum",
    "RHASH": "$ujjud345",
    "USRN": "diam nonumy",
    "USPW": "Lorem Ipsum"
    },
    {
    "ID": "2",
    "Name": "Lorem",
    "Name_ext": "Ipsum",
    "Mail": "smo@localdmn",
    "BG_ID": "1",
    "LLOG": "ea rebum",
    "RHASH": "$ujjud345",
    "USRN": "diam nonumy",
    "USPW": "Lorem Ipsum"
    },
    {
    "ID": "3",
    "Name": "Lorem",
    "Name_ext": "Ipsum",
    "Mail": "smo@localdmn",
    "BG_ID": "1",
    "LLOG": "ea rebum",
    "RHASH": "$ujjud345",
    "USRN": "diam nonumy",
    "USPW": "Lorem Ipsum"
    }
    ]
    }

Thanks for any hints!

Best regards,
Stephan

This question has an accepted answers - jump to answer

Answers

  • DaimianDaimian Posts: 62Questions: 1Answers: 15

    First,
    If you are using Datatables 1.10 you are using the wrong options "sAdjaxSource" for example. If your using 1.9.x then ignore this and move to #2 below....

    Second (and more important),
    Your JSON is not formatted correctly. See this example for fomatting: http://datatables.net/examples/ajax/objects.html

  • paaypaay Posts: 3Questions: 1Answers: 0

    Hi Daimian,

    Thanks for your quick reply! I am indeed using Datatables 1.10, so I have changed it to just "ajax" now, this did not bring any change though.

    Also, I don't see how my JSON is formatted incorrectly. I have compared every line to the example you mentioned, and I do not see any issues.

    Here is a better view at my JSON code:
    http://pastebin.com/t94G0rLD

    Many thanks,
    Stephan

  • DaimianDaimian Posts: 62Questions: 1Answers: 15
    Answer ✓

    Your JSON must be in this type of format:

    {
      "data": [
        {
          "name": "Tiger Nixon",
          "position": "System Architect",
          "salary": "$320,800",
          "start_date": "2011/04/25",
          "office": "Edinburgh",
          "extn": "5421"
        },
        {
          "name": "Garrett Winters",
          "position": "Accountant",
          "salary": "$170,750",
          "start_date": "2011/07/25",
          "office": "Tokyo",
          "extn": "8422"
        }]
    }
    
  • paaypaay Posts: 3Questions: 1Answers: 0

    Ahhh Alright, it specifically has to be "data" and cannot be e.g. "users".
    Thanks man, sometimes it's really the small things that keep you up all night :-).

  • DaimianDaimian Posts: 62Questions: 1Answers: 15

    No problem :)

    Sometimes you just need to talk it through with someone to realize what you overlooked.

This discussion has been closed.