Datatable JSON With Dynamic Array Names Datatable JSON With Dynamic Array Names json json

Datatable JSON With Dynamic Array Names


Your problem is, that your result is a kind of dictionary inside an arrays first item. You could sanitize the data in a dataSrc callback :

var table = $('#headlines-table').DataTable( {  ajax: {    url: '/php/rt.php',    dataSrc: function(d) {      var result = [];      for (var prop in d.data[0]) {        result.push(d.data[0][prop].quote);      }      return result;    }  },  columns: [    { data: "symbol" },    { data: "latestPrice" },    { data: "latestVolume" },    { data: "avgTotalVolume" }  ]})

The above returns an array on the form

[{ symbol: '..', latestPrice: '..' , latestVolume: '..', .. }, { .. }, ..]

here is a demo -> http://jsfiddle.net/2umtx1a7/