Picking data from a selected row of a dynamic table

1

I have a table, which I include the data dynamically in a table. I include in this way, I include in the first column the checkboxes:

$("#tablepesquisaprodutos").append("<tr class='item'>"
                    + "<td>" + "<input type='checkbox' class='link-check' />" + "</td>"
                    + "<td>" + CodigoProduto + "</td>"
                    + "<td>" + DescricaoProduto + "</td>"
                    + "</tr>")

It works perfectly, but I need to checkbox, I can delete or edit the line (opening a modal with the line data), how can I do it? Delete I get by a button, I do it this way:

  $(function () {
    $(document).on('click', '.link-excluir', function (e) {
        e.preventDefault(); // isso aqui impede do '#' fazer o link pular
        var $el = $(this);
        $el.closest("tr").fadeOut(500, function () {
            $el.remove();
        })
    })
})

In case I have the link to delete on the line, I need to select the line, and then click the action button, or delete or change.

    
asked by anonymous 31.08.2018 / 17:39

1 answer

0

I was able to delete, throwing the line in a global variable, in this way, and then when I click the button, I execute the delete function:

   $(function () {
    $(document).on('click', '.link-check', function (e) {
        $thatRow = $(this);
    })
})

And here is the function on the button to delete the line.

    function ExcluirProdutoPedido(linha) {
    $thatRow.closest("tr").fadeOut(500, function () {
        $thatRow.remove();

    })

And here to get the values of the selected line and open the modal with the values:

 $("#idproduto").val($thatRow.closest('tr').find('td').eq(1).text());
    CarregaProduto($thatRow.closest('tr').find('td').eq(1).text());
    $("#qtd").val($thatRow.closest('tr').find('td').eq(3).text());
    $("#precocusto").val($thatRow.closest('tr').find('td').eq(4).text());
    $("#descontop").val($thatRow.closest('tr').find('td').eq(5).text());
    $("#descontov").val($thatRow.closest('tr').find('td').eq(6).text());
    $("#icms").val($thatRow.closest('tr').find('td').eq(8).text());
    $("#aliquotaicms").html($thatRow.closest('tr').find('td').eq(9).text());
    $("#ipi").val($thatRow.closest('tr').find('td').eq(13).text());
    $("#iss").val($thatRow.closest('tr').find('td').eq(11).text());
    $("#dataentrega").val($thatRow.closest('tr').find('td').eq(17).text());

    abreModalAdd();
    
31.08.2018 / 21:11