0
Good night all right ?
I’m trying to create a direct table in Java and include a column with a button, but I couldn’t create it the way I need to.
the most I could was to put the button has all the cells of the table, but I need to put only in the first column
could help me?
function criarTabela(conteudo) {
var tabela = document.createElement("table");
var thead = document.createElement("thead");
var tbody=document.createElement("tbody");
var thd=function(i){return (i==0)?"th":"td";};
for (var i=0;i<conteudo.length;i++) {
var tr = document.createElement("tr");
for(var o=0;o<conteudo[i].length;o++){
var t = document.createElement(thd(i));
t.innerHTML = "<td><button onclick='alert('$id')'>$id</button></td>"
var texto=document.createTextNode(conteudo[i][o]);
t.appendChild(texto);
tr.appendChild(t);
}
(i==0)?thead.appendChild(tr):tbody.appendChild(tr);
}
tabela.appendChild(thead);
tabela.appendChild(tbody);
return tabela;
}
document.getElementById("tabela").appendChild(criarTabela([
["id", "nome", "idade"],
[1, "matheus", 16],
[2, "cristian", 16],
[3, "pedro", 10],
[4, "henrique", 10]
]));
<div id="tabela"></div>
because it does not use a
if(o==0)
to know that it is the first column?– Ricardo Pontual
would look like this? if(o==0) t.innerHTML = "<td><button onclick='Alert('1')'>id</button></td>"
– Fragosojp