0
How do I automatically set a date and time in my html table? Doing it by js.
I created a table by js and entered in it data from my API, only that this data goes to the TD part of the table, and I need to put the date and time that this was entered, and I have to put in the TH part of the table.
<tr class="cliente">
<th class="cor">Quantidade</th>
</tr>
<tr class="clientess">
<th class="cor">Nº.Pedido</th>
</tr>
Then this part of th has to automatically go to date and time. td then I put by javascript:
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;
}
Then I pulled the 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);
// AdicionaNova();
// adicionaClientesNaTabelaViagemStatus(clientes_1);
console.log("ola4");
}
});
And I made a variable to add the time and date:
var data = new Date();
var dia = data.getDate();
var mes = data.getMonth();
var ano = data.getFullYear();
var hora = data.getHours();
var min = data.getMinutes();
var seg = data.getSeconds();
var str_data = dia + '/' + (mes+1) + '/' + ano;
var str_hora = hora + ':' + min;
But I don’t know how to put this in my html table
Ready. I’ve updated the question
– Maria
I can’t touch the answer now, so I deleted it, I’m kind of busy. But soon someone should help
– Wallace Maxters
<th class="color">Quantity</th> </tr> <tr class="clientess"> <th class="color">Nº.Request</th> </tr> the part I want to modify is this one, there instead of ta written "quantity" etc., would be the current time and date. Example: https://www.google.com/search?q=rastreamento+correios&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjc4dzk_KnXAhWJF5AKHTPAJQQ_AUIDSg&biw=1440&bih=769#imgrc=okNvb_6mEcgjQM:
– Maria
is that I need to put on th of the table, but the table has class yes. <table class="table" width="100px" align="center"> <thead> <tr class="client"> <th class="color">Quantity</th> </tr>
– Maria
I made an example of how you can assign the date value to a column, I didn’t know if it was to create a new column, I also suggest using id instead of class if the table is unique. Without further information my reply will be limited to what I posted.
– Caique Romero