jquery - Datatable populated by null, not by JSON -


summary

i'm trying populate datatable javascript array containing json. i'm looping through , creating array json inide. when pass datatable, correctly counts rows, not populate them.

you can see in screen capture below. data below table array being outputted onto screen.

enter image description here

code snippets

$(document).ready(function() {     $('#content').append( '<br><table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );     $('#example').datatable({          "aadata" : x, // array containing json          "aocolumns": [                      { "stitle": "id", "mdata" : "id", sdefaultcontent: "n/a" },             { "stitle": "status", "mdata" : "status", sdefaultcontent: "n/a" },             { "stitle": "date", "mdata" : "date", sdefaultcontent: "n/a" }             ]     }); }); 

i passed json through http://jsonlint.com/, came fine.

example json

{"id":"test","status":"test","date":"test"} 

each json string in array represents row in datatable.

some testing

manually putting in json works fine, so...

"aadata" :         [         {"id":"test","status":"test","date":"test"},         {"id":"test","status":"test","date":"test"},         {"id":"test","status":"test","date":"test"},         {"id":"test","status":"test","date":"test"},         ], 

enter image description here

final thoughts

so array seems outputting correctly, , datatable seems take json manually. somewhere inbetween, not working. thoughts either on json formatting or way pull array json inside. aadata: doesn't seem handling right.

i'll happy answer more questions or post more code/pics. thanks

aadata array of array. aadata should more like:

x = [["test", "test", "test"],["id", "status", "date"],["123", "456", "789"]]; 

if want create data:

//jsonlist = array of json objects x = []; for(var = 0; < jsonlist.length; i++){     x.push([jsonlist[i].id, jsonlist[i].status, jsonlist[i].date]); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -