1
I am creating a dynamic table that from the values of an object, but when generating the table it is not shown. Follow the code:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="batata.js"></script>
</head>
<body>
<div id="tbldados"></div>
</body>
</html>
--------------------------------------------------------------------------------
var dados =[{
"N1":" CONTROLE DE GESTÃO ORCAMENTARIA CONCESSÕES - INDICADORES / 2017 (MILHARES R$)",
"N2":" ",
"N3":"A1 - ATIVIDADE CORE",
"ANO_ANTERIOR":1214363,
"ANO_ATUAL":1335800,
"VAR":121437,
"JAN":2388000,
"FEV":2268000,
"MAR":1728000,
"ABR":2424000,
"MAI":1464000,
"JUN":2124000,
"JUL":1212000,
"AGO":1356000,
"SET":2400000,
"OUT":1800000,
"NOV":0,
"DEZ":0,
"TOTAL":456291000
}]
function createTable(obj){
// Criar a table
$('#tbldados').append('<table></table>'); // Adiciona a tabela ao body
var table = $('#tbldados').children('table'); // Seleciona a tabela
// Criar o head da table
var thead = "<tr>";
for (coluna in obj[0]) {
thead += "<th>" + coluna + "</th>";
}
thead += "</tr>";
$("<table>").show();
//Criar o body da table
var tbody = "<tr>";
obj.forEach(function(linha,) {
for (item in linha) {
tbody += "<td>" + linha[item] + "</td>";
}
tbody += "</tr>";
})
// Adiciona a tabela completa ao body
}
$(document).ready(function(){
createTable(dados);
});
Hello, I do not understand very well your problem, try to explain a little better
– PauloHDSousa
opa blz paulo and the next I have the "data" and I want to create a dynamic table with this data but it is not displaying my table in html I would like to know what is missing put $(Document). ready and all however not displaying the table
– Ubiratan Felipe
Does the header appear? The tbody you mount but not enough to adopt to the table.
– bfavaretto
nothing comes up ,I give append
– Ubiratan Felipe