Object Subarrays example works - sortof
Object Subarrays example works - sortof
spacehunter
Posts: 4Questions: 0Answers: 0
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]
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]
This discussion has been closed.
Replies
[code]
"aaData": this.testData.aaData,
[/code]
Allan
I was using 'sName' instead of 'mDataProp' properties.