Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82314

DataTable data source JSON Array without AJAX

$
0
0

I have successfully created a table with JSON Array data from a SQL database.

I have a file, data.php, that builds the array, which I then refer to with ajax.url.
$('#table').DataTable( { "ajax": { "url": "data.php", "dataSrc": "" },
My dataset is along the lines of:

[{"Date":"2018-01-19","ID":"4","Start":"2018-01-19 23:06:44"..........}]

For continuity/simplicity with existing pages, I would really like to generate the Array in the same php file as the table. I do this with javascript charts, but for the life of me I cannot get it to work with DataTable. I have tried many variants, including:

var tableData = <?php echo json_encode($jsonArray);?>; $(document).ready(function() { $('#table').DataTable( { "data": tableData },

I believe the problem lies in that my array is labeled and without a {"data": starting it off. This is what ajax.dataScr="" accomplishes. How can I work around this with an internally generated array?

Thanks for any pointers!


Viewing all articles
Browse latest Browse all 82314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>