I am having a JSON file with the following values and I am trying to fill the DataTable with the values of the JSON file.
I would like the DataTable to be of the format with 3 columns (Color, Size, Quantity).
An example would be Red, Small, 100 and Red, Medium, 200.
However, these 3 columns are within the JSON object "invSelectionCount" as shown in my JSON file. How do I iterate through the JSON file to manipulate the object within it to fill up the DataTable?
AJAX Call
$.ajax({
'url': 'http://localhost:8080/Retail-war/webresources/products/getProduct/' + productId,
'method': 'GET',
'contentType': 'application/json; charset=utf-8',
'headers': {"Authorization": 'Bearer ' + sessionStorage.getItem('accessToken')},
}).done( function(data) {
$('#product-inventory-level').DataTable( {
"data": [data],
"columns": [
{ "data": "invSelectionCount"},
{ "data": "invSelectionCount"},
{ "data": "invSelectionCount"}
],
})
})
JSON File
{
"productId": 1,
"originalPrice": 59.9,
"currentPrice": null,
"productStatus": "LISTED",
"discount": null,
"productVol": null,
"invSelectionCount": {
"red=small": 100,
"red=medium": 200
},
}