How do I display data if that data is a nested object of the returned data?
How do I display data if that data is a nested object of the returned data?
So I have an ajax call that is returning data that contains two objects at the root. One is LastRefresh which is just the number of ticks and I'm not using it with my DataTable but I am using elsewhere. The other is a list of strings (SKUs) which I want to display in a DataTable. The data comes back fine but I haven't been successful yet in having datatables use the nested object called SKUs.
fbaSKUTable = $('#fbaSKUs').DataTable({
ajax: {
'url': '/api/FBA/RefreshSKUS',
'dataSrc': 'skuData',
'type': 'GET',
'success': function (data) {
skuData = JSON.stringify(data.SKUs);
storage.setItem("lastRefresh", JSON.stringify(data.LastRefresh));
storage.setItem("fbaSKUs", JSON.stringify(data.SKUs));
},
'failure': function (data) {
console.log('failure');
}
},
"columns": [
{"SKU": "SKU"}
]
});
Here is some sample data
{"LastRefresh":"636826452200968391","SKUs":[{"SKU":"AB-BROWN"},{"SKU":"ZAR-FEO1"},{"SKU":"ZZZ-FROST"}]}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Just to make it easier to see here is the data:
You have a few config issues.
ajaxoption thesuccessfunction should not be used but instead theajax.dataSrccan be used in its place.failurefunction to jQuery Ajax. I believe you want to use theerrorfunction.skuDataobject. You will want to useSKUsinstead, for exampledataSrc: "SKUs".{"SKU": "SKU"}in the columns config is not a valid option. You are to use thecolumns.dataoption, for example:{"data": "SKU"}.I haven't tested this so some adjustments may need to be made but I think you will want something more like this:
Kevin
Thank you so much! That worked perfectly!