how to get nested array of objects in the table
how to get nested array of objects in the table
schinamanagonda
Posts: 38Questions: 5Answers: 0
var reportJSON ;
$.getJSON('http://localhost:63963/ProductionProjection/GetReportData?startDate=' + $("#startDate").val() + '&&endDate=' + $("#endDate").val(), function (data) {
reportJSON = data;
//document.write(reportJSON.reportDataDTOs[0].JobNumber);
table = GetdataTable(reportJSON);
table.draw();
});
table = $('#dataTable').DataTable({
//columns: [
// { data: "reportJSON.reportDataDTOS.0.JobNumber"},
// { data: "reportJSON.reportDataDTOS.0.Work" },
// { data: "reportJSON.reportDataDTOS.0.BatchDate" },
// { data: "reportJSON.reportDataDTOS.0.QtyToRun" },
// { data: "reportJSON.reportDataDTOS.0.Part" },
// { data: "reportJSON.reportDataDTOS.0.Description" },
// { data: "reportJSON.reportDataDTOS.0.CustomerName" },
// { data: "reportJSON.reportDataDTOS.0.Pallets" },
// { data: "reportJSON.reportDataDTOS.0.Gallons" },
// { data: "reportJSON.reportDataDTOS.0.GallonsPerCase" },
// { data: "reportJSON.reportDataDTOS.0.Status" },
//],
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Replies
This example may help, it's showing next data.
It also looks like there may be an issue with your data if the next record has values like:
DataTables expects the records to be in an array, so you'll need to convert that numeric indexing into an array structure. This example from this thread may help, as it's demonstrating how that could be done
Colin
this example didnt help even before
i have an object which has 3 lists of data return by the controller and trying to display each single list in a different datatable.
reportJSON.reportDataDTOs[0].JobNumber this value shows up in browser but not in datatable how to display the whole array list of objects in reportDataDTO. please help
This example shows using jQuery ajax() to fetch the data and initializing the Datatable using
data
to populate the Datatable:https://live.datatables.net/huyexejo/1/edit
You will need to do something similar by moving your initialization code within the
$.getJSON()
function initialize each Datatable withdata
pointing to the appropriate object.Kevin
got it resolved before i was generating the jsonresponse from controller changed it to object with array of objects it worked. Thanks