Json with different number of items. How generate a table ?

Json with different number of items. How generate a table ?

arteqwarteqw Posts: 2Questions: 0Answers: 0
edited August 2012 in General
Hello!

I am new to DataTables, BTW great project!

I have problem with generate a table, when number of items in json data is different.

eg.
[code]
'[{"temp": 18.6, "light": 616, "nodeid": "node2", "press": 1003.5, "humi": 92.5, "date": "26/08/2012 15:11", "batvol": 423}]'
[/code]
and
[code]
'[{"date": "26/08/2012 15:14", "nodeid": "node5", "temp": 23.9}]'
[/code]

Now i realize it by code:
[code]

testdata = {{ last }};
console.log(testdata);
$('#ttable').dataTable({
"aaData":testdata,
"bFilter": false,
"bSearchable":false,
"bInfo":false,
"bPaginate": false,

"aoColumns":[
{"mDataProp":"date"},
{"mDataProp":"nodeid"},
{"mDataProp":"temp"},
{"mDataProp":"light"},
{"mDataProp":"press"},
{"mDataProp":"humi"},
{"mDataProp":"batvol"}]
});

[/code]

This work byt got awful error like:

[code]
'DataTables warning (table id = 'ttable'): Requested unknown paramater 'light' from data source for row 1'
[/code]

There is any fix or different way to display dynamic items in json data in one table?

You are my last hope...

Replies

  • allanallan Posts: 63,504Questions: 1Answers: 10,471 Site admin
    You can use sDefaultContent for columns where JSON properties are optional. Just setting it to an empty string for example.

    Allan
  • arteqwarteqw Posts: 2Questions: 0Answers: 0
    It works :) Thanks!
This discussion has been closed.