title: DataTables ajax on nested data
body: <p>I am using DataTables ajax to fill a table. I was following <a href="https://datatables.net/examples/ajax/objects_subarrays.html" rel="nofollow noreferrer">this example</a> and it works if my json looks like their example, however my 'data' is a nested object in my json and then it is not able to fill the table because fails in getting the values from the json.</p>
  
  <p>This json works:</p>
  
  <pre><code>{
    "data": [
         {"id": "myid1", "name": "name1"},
         {"id": "myid2", "name": "name2"}
         ]
  }
  </code></pre>
  
  <p>But my json looks like this, and it does not work</p>
  
  <pre><code>{
   "result": {
      "data": [
          {"id": "myid1", "name": "name1"},
          {"id": "myid2", "name": "name2"}
          ]
      }
   }
  </code></pre>
  
  <p>That's my html (which works with the first json):</p>
  
  <pre><code>&lt;table id="myTable" class="tabletable-bordered dataTable"&gt;
      &lt;thead&gt;
          &lt;tr&gt;                 
             &lt;th&gt;name&lt;/th&gt;
             &lt;th&gt;id&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>And that's my js:</p>
  
  <pre><code>$('#myTable').DataTable( {
          "ajax": "/names",
          "processing": true,
          "dataSrc" : "result.data",
          "columns": [
              { "data": "name" },
              { "data": "id" }
          ]
      } );
  </code></pre>
  
  <p>As you can see I try to access to my nested <code>data</code> by setting <code>dataSrc</code> to <code>result.data</code>, but nothing is shown in the table.</p>
  
  <p>I cannot change the format of the json response, do you know if then is not possible to use DataTables ajax with this json? Thanks!</p>
  
  <hr>
  
  <p><strong>MY SOLUTION</strong></p>
  
  <p>Finally (before getting an answer to my post) I went with the following solution, I first make an ajax call and then on success I create my DataTable.</p>
  
  <p>so I only changed my js to this one:</p>
  
  <pre><code>$.ajax({
      type: "GET",
      url: '/names',
      dataType: "json",
      contentType: "application/json; charset=utf-8",
      success: function (data) {
          var myData = data.result.data;
          $('#myTable').DataTable({
              "data": myData,
              "columns": [
                      { "data": "id" },
                      { "data": "name"},
               ]
            });
       }
  });
  </code></pre>