complex json to datatable

complex json to datatable

MCardona81MCardona81 Posts: 2Questions: 1Answers: 0
edited April 2022 in Free community support

Hi

Im having issues to fill a datatable with this json . My API retunrs something like this :

{
   "statusCode":200,
   "success":true,
   "messages":[
      "Estudios obtenidos exitosamente !"
   ],
   "data":{
      "filas_obtenidas":1,
      "estudios":[
         {
            "informe":1960421,
            "servicio":"Rayos X",
            "estudio":"RADIOGRAFIA DE TOBILLO (AP, LATERAL Y ROTACION INTERNA)",
            "fecha":"2018-08-24"
         }
      ]
   }
}

But the datatable just won get any data .

This si the code for the datatable

        tabla = $('#tabla_resultados').DataTable({
          "processing": true,
          "ajax": url,
          dataSrc: "data",
          contentType: "application/json; charset=utf-8",
        dataType: "json",
          "columns": [
            { "data": "informe" },
            { "data": "servicio" },
            { "data": "estudio" },
            { "data": "fecha" }
            
          ]
        });

Any help or suggestion would be appreciated

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

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

    Try changing the value of dataSrc from "data" to "data.estudios" - that should do the trick,

    Colin

  • MCardona81MCardona81 Posts: 2Questions: 1Answers: 0

    Thank you very very much !
    :)

Sign In or Register to comment.