I am trying to display the dataset inside the cartoDB as HTML table. When i give request to the postgre database by SQL API, it is returning as the format (json) below in the snapshot. I want the returning dataset to be displayed as HTML table in the browser. I had tried with the below code but it is displaying table for var myList=[{"name" : "abc", "age" : 50},
{"age" : "25", "hobby" : "swimming"},
{"name" : "xyz", "hobby" : "programming"}];
But its not displaying for the below format.
And code i had tried is
<script type="text/javascript">
data1 = "transit_point_region_1";
json_link = 'http://development.localhost.lan:8080/api/v2/sql?q=SELECT * FROM ' + data1;
var data = $.getJSON(json_link);
// Builds the HTML Table out of data.
function buildHtmlTable() {
var columns = addAllColumnHeaders(data);
for (var i = 0 ; i < data.length ; i++) {
var row$ = $('<tr/>');
for (var colIndex = 0 ; colIndex < columns.length ; colIndex++) {
var cellValue = data[i][columns[colIndex]];
if (cellValue === null) { cellValue = ""; }
row$.append($('<td/>').html(cellValue));
}
$("#excelDataTable").append(row$);
}
}
function addAllColumnHeaders(data). {
var columnSet = [];
var headerTr$ = $('<tr/>');
for (var i = 0 ; i < data.length ; i++) {
var rowHash = data[i];
for (var key in rowHash) {
if ($.inArray(key, columnSet) === -1){
columnSet.push(key);
headerTr$.append($('<th/>').html(key));
}
}
}
$("#excelDataTable").append(headerTr$);
return columnSet;
}
</script>
</head>
<body onLoad="buildHtmlTable()">
<table id="excelDataTable" border="1">
</table>