0
I’m pulling an API and putting its data inside a table, but this data goes to the table part that is td, but I want to put the date that the data were implemented there, then the date would be in th.
Currently my code is like this:
<div class="container">
<div class="table-responsive">
<table class="table" width="100px" align="center">
<thead>
<tr class="cliente">
<th class="cor">Quantidade</th>
</tr>
<tr class="clientess">
<th class="cor">Nº.Pedido</th>
</tr>
<tr class="fiscal">
<th class="cor">Nota Fiscal</th>
</tr>
<tr class="entprevista">
<th class="cor">Entrega Prevista</th>
</tr>
<tr class="data">
<th class="cor">Data</th>
</tr>
</thead>
</table>
</div>
</div>
PULLING API
function load() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "API AQUI");
xhr.addEventListener("load", function() {
var resposta = xhr.responseText;
console.log("ola1");
var clientes = JSON.parse(resposta);
console.log("ola2");
console.log(clientes);
for (var i =0; i < 1; i++){
console.log("ola3");
var clientes_1 = clientes.TRACKER[i];
adicionaClienteNaTabelaViagem(clientes_1);
adicionaClienteNaTabelaViagemLogo(clientes_1);
AdicionaNotaFiscal(clientes_1);
AdicionaEntPrevista(clientes_1);
AdicionaStatus(clientes_1);
}
});
xhr.send();
}
window.onload = load;
SOME DATA I PUT IN THE TABLE TD
function AdicionaNotaFiscal(fiscal) {
var notaTr = fiscalTr(fiscal);
var tabelas = document.querySelector(".fiscal");
tabelas.appendChild(notaTr);
}
function fiscalTr(fiscal) {
var notaTr = document.createElement("tr");
notaTr.classList.add("fiscal");
notaTr.appendChild(notaTd(fiscal.NFISCA, "info-nota-fiscal"));
return notaTr;
}
function notaTd(dado, classe) {
var teste = document.querySelector(".fiscal");
var td = document.createElement("td");
td.classList.add(classe);
td.textContent = dado;
return td;
}
There on th that written "quantity", "invoice"... I wanted it to be the date of the day that I posted the api
already tried with input?
Input type = DateTime-Local
– Felipe Deolindo
No. That would be inside th?
– Maria
excuse read your wrong question, you want the system to run automatically right? I thought it was pro user to select the date and time
– Felipe Deolindo
will have to be a
.js
to do this routine– Felipe Deolindo
Exactly. Then I can’t do it
– Maria
look at this example here see if you can insert it in your code (https://temptable.com.br/2015/11/display-data-e-hora-actual-em-html.html)
– Felipe Deolindo
I’ve tried this one, it’s not the way I want it
– Maria
I found a very simple code here and very efficient
var teste = new Date()
document.write(teste.toLocaleString());
– Felipe Deolindo
True. The only problem is how do I put this to the HTML table there
– Maria