Using .getJSON with a datatable
Using .getJSON with a datatable
$I am trying to fill a datatable with the JSON that has being returned but I am runnign into problems, I have tried to do the following (i am using highcharts aswel)
(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function (data) {
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
name: 'AAPL',
data: data,
tooltip: {
valueDecimals: 2
}
}]
});
// Create the datatable
var rows = {
dataRows: []
};
for (var i = 0; i < data.length; i++) {
var item = data[i];
rows.dataRows.push(item);
}
alert(rows);
$('#example').dataTable({
"aaData": [
rows.dataRows
],
"aoColumns": [
{ "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" }
]
});
I'm not sure what I'm doing wrong or if there is a better way to populate a data table with JSON?
Also I saw this:
var laTabla;
$(document).ready(function() {
/*This does work, even fnRender */
$.getJSON( 'ajax/getdata.jsp', null, function( json ) {
laTabla= $('#example').dataTable(json);
} );
});
Should i be using something more along these lines and if so how?
Any help wou dbe appreciated thanks!
(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function (data) {
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
name: 'AAPL',
data: data,
tooltip: {
valueDecimals: 2
}
}]
});
// Create the datatable
var rows = {
dataRows: []
};
for (var i = 0; i < data.length; i++) {
var item = data[i];
rows.dataRows.push(item);
}
alert(rows);
$('#example').dataTable({
"aaData": [
rows.dataRows
],
"aoColumns": [
{ "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" }
]
});
I'm not sure what I'm doing wrong or if there is a better way to populate a data table with JSON?
Also I saw this:
var laTabla;
$(document).ready(function() {
/*This does work, even fnRender */
$.getJSON( 'ajax/getdata.jsp', null, function( json ) {
laTabla= $('#example').dataTable(json);
} );
});
Should i be using something more along these lines and if so how?
Any help wou dbe appreciated thanks!
This discussion has been closed.