1

I have this code:

testdata = [{
    "hasresults": true,
    "resultscount": 5,
    "dob": null,
    "chart": {
        "rows": [
            {
                "chart": "BAR000",
                "firstname": "RUSSELL",
                "lastname": "BARON"
            },
            {
                "chart": "BAR001",
                "firstname": "BRUSELL",
                "lastname": "BARON"
            },
            {
                "chart": "BAR002",
                "firstname": "GARY",
                "lastname": "BARON"
            }
        ]
    }
}];

$('#test').dataTable({
    "aaData": testdata,
        "aoColumns": [{
        "mDataProp": "chart"
    }, {
        "mDataProp": "firstname"
    }, {
        "mDataProp": "lastname"
    }]
});

Can someone help me why is this not working? It seems that if I removed the following, it will work:

"hasresults": true,
"resultscount": 5,
"dob": null,
"chart": {

Not working fiddle

Working fiddle

4
  • Try switching "dob": null to "dob": empty See this for resources on JSON types. Commented Mar 2, 2015 at 19:31
  • Tried it but doesn't work either. I'm thinking mDataProp should have chart.rows.chart but it doesn't work either. Commented Mar 2, 2015 at 20:56
  • What is the specific exception it's giving you? Commented Mar 2, 2015 at 22:08
  • DataTables warning: table id=test - Requested unknown parameter 'lastname' for row 0. For more information about this error, please see datatables.net/tn/4 Commented Mar 3, 2015 at 13:46

1 Answer 1

2

You just need to address testdata the correct way. testdata is an array holding an object which have another object, chart, holding an array, rows.

$('#test').dataTable({
    "aaData": testdata[0].chart.rows, //<------
    "aoColumns": [{
        "mDataProp": "chart"
    }, {
        "mDataProp": "firstname"
    }, {
        "mDataProp": "lastname"
    }]
});

Your code working here -> http://jsfiddle.net/j1fvL96e/

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Was close using it in the mDataProp but instead it should be in the aaData as you indicated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.