Loading Datatables from JSON Problem

Loading Datatables from JSON Problem

VibbenVibben Posts: 2Questions: 1Answers: 0

Hello,

I'm trying to take the following formatted JSON:

{
"status": "success",``
"data": {
"query": {
"numrows": 100,
"queryname=": "X_SR_OPEN_CLASSES",
"rows": [
{
"attr:rownumber": 1,
"STRM": "2203",
"CAMPUS": "CITY",
"SUBJECT": "BCAS",
"CATALOG_NBR": "  85",
"CRSE_DESCR": "Carpenter Apprentice I",
"CLASS_NBR": 27798,
"SEATS": "25",
"ROOM": "City-CLSRM",
"LOCATION": "Off Campus",
"START_DT": "2020-01-21",
"END_DT": "2020-06-01",
"EXPR29_29": "17:00",
"EXPR30_30": "18:25",
"EXPR31_31": "TTh",
"NAME": "SAMPLE, NAME",
"EMAIL_ADDR": "CSDEV92@erpdev.loc",
"EXPR19_19": ""
},

But when I load the tables I get a blank table, no error dialog pops up. Here's the javascript I'm using:

<script>
  $(document).ready(function() {
    $('#example').DataTable( {
      "processing": true,
      "ajax": {
        "url": "open_classes.json",
        "dataSrc": "rows",
      },
      "columns": [
        { "data": "STRM" },
        { "data": "SUBJECT" },
        { "data": "CATALOG_NBR" },
        { "data": "CRSE_DESCR" },
        { "data": "CLASS_NBR" }
      ]
    } );
  } );
</script>

Any assistance would be greatly appreciated.

Thank you.

This question has accepted answers - jump to:

Answers

  • ntstravelntstravel Posts: 15Questions: 2Answers: 1
    edited February 21

    Have you tried changing your dataSrc property to:

    "dataSrc": "data.rows"
    
  • allanallan Posts: 51,440Questions: 1Answers: 7,758 Site admin
    Answer ✓

    It looks like it is nested even more than that (although hard to see without indentation):

    dataSrc: 'data.query.rows'
    

    should do it.

    Allan

  • kthorngrenkthorngren Posts: 8,197Questions: 25Answers: 1,844
    Answer ✓

    Looks like you JSON is structured like this:

    {
        "status": "success",
        "data": {
            "query": {
                "numrows": 100,
                "queryname=": "X_SR_OPEN_CLASSES",
                "rows": [{
    

    To update @ntstravel 's answer looks like ajax.dataSrc needs to be "dataSrc": "data.query.rows".

    Kevin

  • VibbenVibben Posts: 2Questions: 1Answers: 0

    Ah, that worked! Thank you for your help, was getting tunnel vision looking at it for so long.

Sign In or Register to comment.