Deep, deep data
Deep, deep data
mmeadow5
Posts: 5Questions: 0Answers: 0
I am trying to map a JSON structure where a subarray of hashes determine the row. I suspect this is too complex, and that I will need to format the data for datatables server-side, but here goes. . .
Sample JSON:
[code]
{
"arrayOuter": [{
"name": "bob",
"date": "today",
"arrayInner": [{
"hashInner0.0": "zero",
"hashInner0.1": "one",
}, {
"hashInner1.0": "zero",
"hashInner1.1": "one",
}, { . . .
[/code]
The table columns would then be:
| arrayOuter.name | arrayOuter.date | arrayInner.hashInner0.0 | arrayInner.hashInner0.1 |
| arrayOuter.name | arrayOuter.date | arrayInner.hashInner1.0 | arrayInner.hashInner2.1 |
| arrayOuter.name | arrayOuter.date | arrayInner.hashInner3.0 | arrayInner.hashInner3.1 |
I have tried several options, including sAjaxDataProp to set the source as arrayInner, but keep getting an error of:
"Cannot read property 'length' of undefined"
Is there any way for this JSON structure to map directly onto a datatables object?
Sample JSON:
[code]
{
"arrayOuter": [{
"name": "bob",
"date": "today",
"arrayInner": [{
"hashInner0.0": "zero",
"hashInner0.1": "one",
}, {
"hashInner1.0": "zero",
"hashInner1.1": "one",
}, { . . .
[/code]
The table columns would then be:
| arrayOuter.name | arrayOuter.date | arrayInner.hashInner0.0 | arrayInner.hashInner0.1 |
| arrayOuter.name | arrayOuter.date | arrayInner.hashInner1.0 | arrayInner.hashInner2.1 |
| arrayOuter.name | arrayOuter.date | arrayInner.hashInner3.0 | arrayInner.hashInner3.1 |
I have tried several options, including sAjaxDataProp to set the source as arrayInner, but keep getting an error of:
"Cannot read property 'length' of undefined"
Is there any way for this JSON structure to map directly onto a datatables object?
This discussion has been closed.
Replies
[code]
{
"arrayOuter": [{
"name": "bob",
"date": "today",
"arrayInner": [{
"hashInner0": [ "zero" ]
...
[/code]
There is a `[]` option which will effectively pluck properties from arrays - i.e.: `arrayOuter[, ].name` would pluck all `name` parameters and comma separate them.
So yes the basic idea works, but the `.` is already used, so that won't work at the moment (I'll look at adding an escape option in future). If you can change it to `hashInner0-0` then that would work.
Allan
Using "[]" option is almost exactly what is needed, except instead of comma separated, each member should start a new row.
The characters found between the `[` and `]` are used as the delimited, so they can easily be changed.
However, if you want each on a different row - that isn't possible with multi-dimentional arrays. However, based on your data, I guess you might only need the sAjaxDataProp option - set it to `arrayOuter.arrayInner` and it should work just fine.
Allan
Allan
I think you have already answered my question, but here is a less confusing example:
[code]{
"aaData": [{
"engine": "Trident",
"browsers: [{ "browser": "Internet Explorer 4.0",
"platform": "Win 95+",
},{
"browser": "Internet Explorer 5.0",
"platform": "Win 95+",
}]
},{
"engine": "Gecko",
"browsers: [{ "browser": "Firefox 6.0",
"platform": "Linux",
},{
"browser": "Firefox 7.0",
"platform": "Linux",
}]
}]
}
[/code]
The resulting table headers would be:
| Engine | Browser | Platform |
Thanks for all of your help and feedback!
Allan