Check if dynamic table is with data

Asked

Viewed 31 times

1

I have a table which I fill out this way below, I would like to know how I can check if you 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 some ways, but all do not identify the lines, as they are inserted dynamics.

  • 1

    Try it like this: if($("#tablepesquisaprodutos td").length){ // possui colunas }... this will check if it has columns td... if you want to see if you have tr just change the td for tr.

  • It worked fine, thank you.

1 answer

2


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

$("#tablepesquisaprodutos td").length

If you find nothing, you will return 0, soon fits into a if the verification:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.