aData is undefined - can anyone help

aData is undefined - can anyone help

ppsiriusppsirius Posts: 5Questions: 2Answers: 0

I downloade the DataTables and working on examples. I change script to:

$(document).ready(function() {
    $('#example').dataTable( {
        "sAjaxSource": "data/test.txt",
        "sAjaxDataProp": "result",
        "aoColumns": [
            { "result": "id" },
            { "result": "title" },
            { "result": "date" },
            { "result": "price" }
        ]
    } );
} );

and my json file it looks like this

{
    "success": 1,
    "result": [
        {
            "id": "1",
            "title": "Rezerwacja 1",
            "date": 1404165600000,
            "price": 450
        },
        {
            "id": "2",
            "title": "Rezerwacja 2",
            "date": 1404165100000,
            "price": 350
        }
    ],
    
    "message": "Jakiś komunikat"
}

Can anyone tell me how I get this error?

Answers

  • neilrao42neilrao42 Posts: 14Questions: 2Answers: 1
    edited November 2014

    Some references that may help: ajax and nested object data. In your case you might be looking for something like (not sure if it works with the legacy datatables):

    $(document).ready(function() {
        $('#example').dataTable( {
            // ...
            "columns": [
                { "data": "result.id" },
                { "data": "result.title" },
                { "data": "result.date" },
                { "data": "result.price" }
            ]
        } );
    } );
    
  • ppsiriusppsirius Posts: 5Questions: 2Answers: 0

    I change to something like this and it's working :D

       $('#example').dataTable( {
            "sAjaxSource": "data/test.txt",
            "sAjaxDataProp": "result",
            "columns": [
            { "data": "id" },
            { "data": "title" },
            { "data": "date" },
            { "data": "price" }
            ]
        } );

    But now how I can get date format not only numbers 1404165600000?

  • neilrao42neilrao42 Posts: 14Questions: 2Answers: 1

    You can use columns.render to format the date for display.

This discussion has been closed.