Verify if dynamic table is with data

1

I have a table that I fill in this way below, I would like to know how I can check if I have data in it.

  $("#tablepesquisaprodutos").append("<tr class='item'>"
             + "<td>" + "<input type='checkbox' class='link-check' onchange='cbChange(this);' />" + "</td>"
             + "<td>" + CodigoProduto + "</td>"
             + "<td>" + DescricaoProduto + "</td>"
             + "<td>" + Qtd + "</td>"
             + "<td>" + PrecoCusto + "</td>"
             + "<td>" + DescontoP + "</td>"
             + "<td>" + DescontoV + "</td>"
             + "<td>" + Total.toFixed(2).replace(".", ",") + "</td>"
             + "<td>" + ICMS + "</td>"
             + "<td>" + AliquotaICMS.replace(".", ",") + "</td>"
             + "<td>" + vICMS.toFixed(2).replace(".", ",") + "</td>"
             + "<td>" + ISS.replace(".", ",") + "</td>"
             + "<td>" + vISS.toFixed(2).replace(".", ",") + "</td>"
             + "<td>" + vIPI.toFixed(2).replace(".", ",") + "</td>"
             + "<td>" + QtdFalta + "</td>"
             + "<td>" + ProdutoID + "</td>"
             + "<td>" + DataEntrega + "</td>"
             + "</tr>")

I have tried in some ways, but all of them do not identify the lines, because they are inserted dynamically.

    
asked by anonymous 31.10.2018 / 21:22

1 answer

2

You can count the number of columns ( td ) with:

$("#tablepesquisaprodutos td").length

If it does not find anything, it will return 0 , so it fits in a if check:

if($("#tablepesquisaprodutos td").length){
   // possui ao menos 1 coluna
}
    
31.10.2018 / 21:37