displaying json data
displaying json data

Hi -
I'm trying to take json formatted output from a program, and use datatables to display it.
The program that generates the output is LMOD. You can see a couple examples of the type of json outputted here:
https://lmod.readthedocs.io/en/latest/136_spider.html
How do I ingest (is that the right term) this file into something datatables can parse?
I'm looking at using the AJAX columns stuff, but the json I'm bringing in, isn't as simple as the keypair examples provided...There's a lot of nested stuff, and what appears to be headers which are singular entries (not a pair).
I'm confused on a couple of things. For one, I am not passing an array to datatables, but rather an AJAX object correct?
Do I define the .json file here:
"ajax": "data/objects.txt",
but with it being "ajax": "http://blah.blah/myfile.json"
Any help is appreciated.
This question has accepted answers - jump to:
Answers
So I got this working - for the most part, but I am getting one error:
DataTables warning: table id=example - Requested unknown parameter 'defaultVersionName' for row 1, column
The code is:
<
script>
$(document).ready(function() {
$('#example').DataTable( {
"ajax": {
"url": "software.json",
"dataSrc": ""
},
"columns": [
{ "data": "defaultVersionName" },
{ "data": "package" },
{ "data": "description" }
]
} );
} );
I did notice in my software.json file, that defaultVersionName is missing on some of the entries. Is there a way to ignore the few cases this field is missing?
I think you can use
columns.defaultContent
for this. See the second example in the docs.Kevin
Thank you - that did it.
One last issue. I am trying to pull in nested data from my json file, using the dotted notation,
{
"data": "versions.full",
"defaultContent": ""
},
but it's coming up blank. Looking at the json file I see:
But when I look at it in the browser, I get an array index, 0,1 etc. Do I need to include that index in the dotted notation? The versions range varies in most cases.
thanks.
Hi @tyrrvk ,
I think this example here is what you're after. You need
Cheers,
Colin