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

How to add data with unique keys via JSON/AJAX?

$
0
0

Hi guys!

I'd appreciate any insight here. I have a datatable which uses JSON data and pulls via AJAX.

The goal is to utilize data from arrays with unique key values. Unfortunately, I only get [object Object] as the response.

What would be the best way to pull such data?

Here is my code:
Javascript:

$(function () { $('#example1').DataTable({ "ajax": { "url": "db/data.json", }, "columns": [ { "data": { "CVS": "name" }}, { "data": { "Costco": "name" }} ], 'paging' : true, 'lengthChange': false, 'searching' : false, 'ordering' : true, 'info' : true, 'autoWidth' : false }) })

HTML:

Name

JSON:

{
"data":[
{
"CVS":[
{
"name":"lisinopril"
},
{
"name":"adderall"
}
]
},
{
"Costco":[
{
"name":"ibuprofen"
},
{
"name":"methylphenidate"
}
]
}
]
}

Ultimately, each primary category (CVS, Costco, etc) will have multiple keys, such as 'dosage', but I simplified the code to make it easier to understand what I'm looking to do.

Admittedly, I'm only just now learning the basics of Javascript, let alone libraries/frameworks like datatables, so I sincerely apologize for my lack of understanding. Again, any help/input is highly appreciated.

Thanks,

-Dave


Viewing all articles
Browse latest Browse all 81989

Trending Articles



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