how to get nested array of objects in the table

how to get nested array of objects in the table

schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0
edited September 2023 in DataTables 1.10
 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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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:

    reportJSON.reportDataDTOS.0.JobNumber
    

    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

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    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.

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    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

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948
    edited September 2023

    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 with data pointing to the appropriate object.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    got it resolved before i was generating the jsonresponse from controller changed it to object with array of objects it worked. Thanks

Sign In or Register to comment.