simple object key to table question, although I can't figure it out.
simple object key to table question, although I can't figure it out.
Hello All,
have been struggling with the following and could not find an elegant solution yet.
A simple mapping of key and value
my data (shortened for clarity):
{
"data": [
{
"kernel": "5.4.0-1022-raspi",
"openssl": "1.1.1d",
"systemOpenssl": "1.1.1f",
"systemOpensslLib": "OpenSSL",
"node": "10.19.0",
}
]
}
My table:
$('#tableVersions').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "/api/table/?name=versions",
"dataSrc": 'data'
},
"columns": [
{ "data": "????"}, //<- part I am struggling with would like to output 'kernel' here, so the key
{ "data": "kernel" }, // <!--- dynamic too, I do get output (the value) so I am getting the data. but would like the value
],
} );
I am struggling to get the key/value working in a simple way, I have seen some examples but they look like hacks.
I know I am getting the correct data (as it outputs the 'kernel' value.
I have the idea that I could do something in the ajax call but, again, no clear examples.
tried "0", etc and looked at all the examples I could find (not limited too:
https://datatables.net/manual/ajax#JSON-data-source
https://datatables.net/examples/ajax/objects.html.
No luck so far,
Any tips welcome.
Kind Regards,
Gerrit Kuilder
This question has an accepted answers - jump to answer
Answers
This is the closest example I could find: http://plnkr.co/edit/kVMprP8BZ6aik2DRjh7D?p=preview&preview
I'm not clear what you want to go into that first column. Column 2 is clear,
kernel
, but can you say what you expect for 1?Colin
Hello Colin,
apologies for missing that part:, the end result should be that the first collum contains the name and the second the value
So
ends up as
I tested with 'kernel to ensure/show that I have data...
Regards,
Gerrit Kuilder
Datatables expects this to be in one row:
You don't need to display all of them but this is one row of data.
Datatables doesn't support displaying the above in multiple rows. You could restructure your data to match how you want to display it. Something like this:
Then define your columns like this:
Kevin
Hi All,
thanks for the input, I can indeed better do some preprocessing of the data just to keep the tables a little cleaner.
Regards,
Gerrit Kuilder