Server-side "No matching records found"

Server-side "No matching records found"

adminUser1234adminUser1234 Posts: 6Questions: 1Answers: 0

I've seen a few posts on this but none of them seemed to correspond to the issue I'm having.

Debug Link: http://debug.datatables.net/ibadom

I also ran jsonlint.com to make sure the json is valid, which it is.

I'm stuck on how to get the data to display in dataTables. From everything I can see I am getting a good response from the server-side script although the debugger tells me that there's 0 rows (therein is the problem). I have the appropriate number of columns in the ajax and html code matching the service-side script. This is the data generated by the server-side script:

{
"draw": 1,
"recordsTotal": 1,
"recordsFiltered": 1,
"data": {
"VendorID": "V0000051",
"Name": "STAPLES CONTRACT AND COMMERCIAL INC",
"Mnemonic": "CORPORATE",
"TermsDescription": "INV 2/30 NET 31",
"ActiveYn": "Y"
}
}

I don't get any other error messages so it seems fine. Can anyone suggest next steps to take?

Thank you!

This question has an accepted answers - jump to answer

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    edited October 2014

    Do you have the column data defined? You either need to reset your array keys before your return in the back end, or define them on the front end in the dataTables JS.

    This in the JS:

    columns:[
        {data:"VendorID"},
        {data:"Name"},
        {data:"Mnemonic"},
        {data:"TermsDescription"},
        {data:"ActiveYn"}
    ]
    

    Or this server side on your array of data:

    $data = array_map('array_values', $data);
    return array(
        "data"=>$data
    );
    
  • adminUser1234adminUser1234 Posts: 6Questions: 1Answers: 0

    Could it have anything to do with the fact that the response header "Content Type" is set to text/html? How can I change this and does it matter?

  • adminUser1234adminUser1234 Posts: 6Questions: 1Answers: 0

    @ignignokt:

    My javascript is as follows:

    $(document).ready(function() {
    $('#Test').dataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "tableTestData.php",
    "columns": [
    { "data": "VendorID" },
    { "data": "Name" },
    { "data": "Mnemonic" },
    { "data": "TermsDescription" },
    { "data": "ActiveYn" }
    ],

    });
    

    });

  • adminUser1234adminUser1234 Posts: 6Questions: 1Answers: 0

    sorry about the formatting. This should be better:


    $(document).ready(function() { $('#Test').dataTable( { "processing": true, "serverSide": true, "ajax": "tableTestData.php", "columns": [ { "data": "VendorID" }, { "data": "Name" }, { "data": "Mnemonic" }, { "data": "TermsDescription" }, { "data": "ActiveYn" } ], });
  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    edited October 2014 Answer ✓

    Shouldn't the json reply have the array brackets around your object? That might matter.

    IE:

    "data": [{ "VendorID": "V0000051", "Name": "STAPLES CONTRACT AND COMMERCIAL INC", "Mnemonic": "CORPORATE", "TermsDescription": "INV 2/30 NET 31", "ActiveYn": "Y" }]
    

    instead.

    I believe you'd just have to wrap your return for your data in an array to test that out.

    return array(
        "data"=>array($data)
    );
    

    If that isn't it, then I'm out of ideas for now.

  • adminUser1234adminUser1234 Posts: 6Questions: 1Answers: 0

    yea I might have to look at the format of the json. I have data set to an object but it should probably be an array of objects like this data: [ { } ]

    I'll give it a try and reformat my server-side script output.

  • adminUser1234adminUser1234 Posts: 6Questions: 1Answers: 0

    @ignignokt:

    reformatting the json as an array of objects does indeed work! Thanks for pointing me in the right direction.

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39

    No problem, glad that was it!

This discussion has been closed.