Object Subarrays example works - sortof

Object Subarrays example works - sortof

spacehunterspacehunter Posts: 4Questions: 0Answers: 0
edited February 2012 in General
The example (DataTables-1.9.0/examples/ajax/objects_subarrays.html) works just fine when using the sAjaxSource property. Now, if you alter this example to use static JSON object instead, the data will not render as expected.

Replace the example's script with the following code to reproduce.

[code]

$(document).ready(function() {
this.testData = {
"aaData": [
{
"engine": "Trident",
"browser": "Internet Explorer 4.0",
"platform": "Win 95+",
"details": [
"4",
"X"
]
},
{
"engine": "Trident",
"browser": "Internet Explorer 5.0",
"platform": "Win 95+",
"details": [
"5",
"C"
]
}
]
};

var oTable = $('#example').dataTable( {
"aaData": this.testData,
"aoColumns": [
{ "mDataProp": "engine" },
{ "mDataProp": "browser" },
{ "mDataProp": "platform" },
{ "mDataProp": "details.0" },
{ "mDataProp": "details.1" }
]
} );
} );

[/code]

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    You don't need to wrap it up in aaData when doing it this way. For example to get the above code to work you would use:

    [code]
    "aaData": this.testData.aaData,
    [/code]

    Allan
  • spacehunterspacehunter Posts: 4Questions: 0Answers: 0
    Thanks for the clarification Allan!

    I was using 'sName' instead of 'mDataProp' properties.
This discussion has been closed.