CodeIgniter Forums
going from json to datatable format - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: going from json to datatable format (/showthread.php?tid=69966)



going from json to datatable format - richb201 - 02-03-2018

I am sending a buffer of json data from my codeigniter based app to the client PC's browser. Here is the AJAX that catches it. I am having trouble getting the data out of the json array  and into the datatable format. I have attached a copy of the json that arrives in jsonData and also the AJAX that gets the buffer.  
function drawChart() {
   var jsonData = $.ajax({
   type : "GET",
       url: "<?php echo base_url(); ?>" + "index.php/Configure/snd_json",
      dataType: "json",
    //  jsonp: false,
       cache: false,
       dataSrc: '',
       success: function(jsonData)
           {
       //   var jD = JSON.parse(jsonData);
       // ien=jsonData.length;
           var data = new google.visualization.DataTable(jsonData);
           data.addColumn('string', 'Name');
           data.addColumn('string', 'Manager');
           data.addColumn('string', 'ToolTip');
           for ( var i=0, ien=jsonData.length ; i<ien ; i++ ) {
                data.addRow(jsonData[i]['employee_email'],jsonData[i]['manager_email'],jsonData[i]['employee_title']);
                //   data[i][0] = '<a href="/message/'+json.data[i][0]+'>View message</a>';
                 }

          // var jsonObject=$.parseJSON(jsonData);
           var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
           // Draw the chart, setting the allowHtml option to true for the tooltips.
           chart.draw(data, {});
           },
       error:
          function (jqXHR, textStatus, errorThrown) {
           alert('error');
              // Request failed. Show error message to user.
              // errorThrown has error message, or "timeout" in case of timeout.


          },

       async: false,
       timeout: 10000,

   }).responseText;


The trouble I have is on the line in RED. I don't know how to grab the data in the json buffers so I can copy them to the datatable. I have tried jsonData[i].employee_email too but with no luck. Any help is appreciated.

Thanks, Rich


RE: going from json to datatable format - richb201 - 02-05-2018

Well, I figured it out on my own. Unfortunately I am kind of burned out on the effort it took to do it. Here is how I got it working for others with this same issue.
First I built a array for each line by using var arrJd=(jsonData[i].employee_email, jsonData[i].manager_email,jsonData[i].employee_title);
And then I add the row to the datatable with addRow(arrJd);