Table not loading with returned data

Table not loading with returned data

lassenav@hotmail.comlassenav@hotmail.com Posts: 16Questions: 5Answers: 0

First, thanks, I am really enjoying this compared to .net grid, BUT...
After finally getting past the Invalid JSON error, table wont show data... Using your suggested debug method returned data is
{"d":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","Start date":"2011/04/25","Salary":"$320,800"}]}

My script is:
$(document).ready(function () {
//$('#example').DataTable({ "ajax": "data/arrays.txt" });
$('#example').DataTable({
'ajax':{
'url': 'default.aspx/GetDataTablesTestData',
//'dataSrc': 'd',
//"sAjaxDataProp": "d",
'type': 'POST',
'contentType': 'application/json; charset=utf-8',
'dataType': 'json'

    }
});

});

Any help would be greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,247Questions: 26Answers: 4,929

    It looks like your data source is d instead of the normal data. I think if you uncomment the line 'dataSrc': 'd', it will load the data object using d.

    Kevin

  • lassenav@hotmail.comlassenav@hotmail.com Posts: 16Questions: 5Answers: 0

    Thx for the follow-up K, but...
    As you can see I commented it out, tried it and event (as you suggested), changed the d to data, still no joy.

    {"d":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","Start date":"2011/04/25","Salary":"$320,800"},{"Name":"Airi Satou","Position":"Accountant","Office":"Tokyo","Extn":"5407","Start date":"2008/11/28","Salary":"$162,700"}]}

    I'm posting this JSON, because there is clearly some concept about server-side retrieval I have yet to grasp. This is the JASON return, but what exactly is datatables expecting. I can read/interpret and display this just fine outside of ...

    $('#example').DataTable({
        'ajax':{
            'url': 'default.aspx/GetDataTablesTestData',
            'dataSrc': 'data',
            //"sAjaxDataProp": "d",
            'type': 'POST',
            'contentType': 'application/json; charset=utf-8',
            'dataType': 'json'
    
        }
    });
    
  • kthorngrenkthorngren Posts: 21,247Questions: 26Answers: 4,929

    Maybe you need to define the columns using columns.data.

    Kevin

  • lassenav@hotmail.comlassenav@hotmail.com Posts: 16Questions: 5Answers: 0

    Nothing yet. kind of frustrating, no errors, no display of what appears to be valid JSON.

    My script, just in case I'm not using your suggestion correctly:
    $(document).ready(function () {
    //$('#example').DataTable({ "ajax": "data/arrays.txt" });
    $('#example').DataTable({
    ajax:{
    url: 'default.aspx/GetDataTablesTestData',
    type: 'POST',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json'
    },
    dataSrc: 'd',
    columns: [{'d':'Name'},{'d':'Position'}]
    });
    });

    My HTML (just the table and surrounding div):

    Name Position

    ...and according to chrome, network response
    {"d":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","Start date":"2011/04/25","Salary":"$320,800"},{"Name":"Airi Satou","Position":"Accountant","Office":"Tokyo","Extn":"5407","Start date":"2008/11/28","Salary":"$162,700"}]}

  • kthorngrenkthorngren Posts: 21,247Questions: 26Answers: 4,929
    Answer ✓

    Try changing your columns definition to:
    columns: [{'data':'Name'},{'data':'Position'}]

    Kevin

  • lassenav@hotmail.comlassenav@hotmail.com Posts: 16Questions: 5Answers: 0

    You are my newest and bestest friend!!!! :smile:
    Thank you so MUCH, DUDE I was at a lost.

    Seriously, nice job.

This discussion has been closed.