Can't get data to appear in the table through a AJAX call.

Can't get data to appear in the table through a AJAX call.

phavanagiphavanagi Posts: 13Questions: 5Answers: 0

Hi,

My JSON is in the following format-

"Id":"1:{0410E3B0-6DF5-4DC7-A4E0-B0F1DEB56FA6}",
"Name":"End of Cycle Notification - weekday",
"Path":"JOBS\\adTempus\\End of Cycle Notification - weekday",
"Status":null,
"JobQueue":"Default",
"UserAccount":"DEV_ADTEMPUS_ADMIN","Description":"
    [{Description: "Job "JOBS\Portia\Client Data\Client Data Job Complete" must have succeeded",…},…] (Array1 of JSON)
        0: {Description: "Job "JOBS\Portia\Client Data\Client Data Job Complete" must have succeeded",…}
        1: {Description: "Job "JOBS\OpenSTaARS\OpenSTaARS File Automation" must have succeeded", JobId: null}
    ExecutionHistoryList:[{Machine: "dev2-adtempus", InstanceId: "122", Status: "Skipped",…},…] (Array2 of JSON)
        0:{Machine: "dev2-adtempus", InstanceId: "122", Status: "Skipped",…}
        1:{Machine: "dev2-adtempus", InstanceId: "121", Status: "WaitingForCondition",…}

I want to only display the data ID,Name,Path and JobQueue.
I have written the following dataTable code, but the output is "No data available in the table"

table1= $("#acc").DataTable({
                destroy: true, // To reinitialize the table
                ajax: {
                    url: "http://localhost:57973/api/jobs/jobdetails/" + jobPath,
                    dataSrc: ' '
                },
                columns: [
                    { data: 'Name' },
                    {
                        data: 'Id', render: function (data) {
                            data = data.split("{")[1];
                            data = data.split("}")[0];
                            return data;
                        }
                    },

                    { data: 'JobQueue' },
                    { data: 'Path' },
                    { data: 'UserAccount'}
                   
                ]
            });

Kindly let me know if it is right? Is it possible to use data tables when there are arrays in the JSON data.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    I assume your JSON format looks like this:

    [
      {
        "Id":"1:{0410E3B0-6DF5-4DC7-A4E0-B0F1DEB56FA6}",
    "Name":"End of Cycle Notification - weekday",
    "Path":"JOBS\\adTempus\\End of Cycle Notification - weekday",
    "Status":null,
    "JobQueue":"Default",
    "UserAccount":"DEV_ADTEMPUS_ADMIN","Description":"
        [{Description: "Job "JOBS\Portia\Client Data\Client Data Job Complete" must have succeeded",…},…] (Array1 of JSON)
            0: {Description: "Job "JOBS\Portia\Client Data\Client Data Job Complete" must have succeeded",…}
            1: {Description: "Job "JOBS\OpenSTaARS\OpenSTaARS File Automation" must have succeeded", JobId: null}
        ExecutionHistoryList:[{Machine: "dev2-adtempus", InstanceId: "122", Status: "Skipped",…},…] (Array2 of JSON)
            0:{Machine: "dev2-adtempus", InstanceId: "122", Status: "Skipped",…}
            1:{Machine: "dev2-adtempus", InstanceId: "121", Status: "WaitingForCondition",…}
    
      },
    { next record },
    ]
    

    Looks like you have a space in this dataSrc: ' '. Try removing the space list this dataSrc: ''.

    Kevin

This discussion has been closed.