Note that there are some explanatory texts on larger screens.

plurals
  1. PODatatable populated by null, not by JSON
    primarykey
    data
    text
    <p><strong>Summary</strong></p> <p>I'm trying to populate a datatable with a javascript array containing JSON. I'm looping through and creating the array with JSON inide. When I pass this back to the Datatable, it correctly counts the rows, but does not populate them. </p> <p>You can see this in the screen capture below. The data below the table is the array being outputted onto the screen.</p> <p><img src="https://i.stack.imgur.com/CyBGu.png" alt="enter image description here"></p> <p><strong>Code Snippets</strong></p> <pre><code>$(document).ready(function() { $('#content').append( '&lt;br&gt;&lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt;&lt;/table&gt;' ); $('#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" } ] }); }); </code></pre> <p>I passed the JSON through <a href="http://jsonlint.com/" rel="nofollow noreferrer">http://jsonlint.com/</a>, which came up fine. </p> <p><strong>Example JSON</strong></p> <pre><code>{"ID":"TEST","status":"TEST","date":"TEST"} </code></pre> <p>Each JSON string in the array represents a row in the datatable. </p> <p><strong>Some Testing</strong></p> <p>Manually putting in the JSON works fine, like so...</p> <pre><code>"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"}, ], </code></pre> <p><img src="https://i.stack.imgur.com/HpWUR.png" alt="enter image description here"></p> <p><strong>Final Thoughts</strong></p> <p>So my array seems to be outputting correctly, and the Datatable seems to take the JSON manually. Somewhere inbetween, it is not working. My thoughts are either on the JSON formatting or the way you pull an array with JSON inside. aaData: doesn't seem to be handling it right. </p> <p>I'll be happy to answer any more questions or post more code/pics. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload