Table mounted by input select

Asked

Viewed 63 times

0

My problem here is that I mount a table through an array received by Ajax,have 2 problems:

first Every time I select an item in select the Table should reset and take the new data, the way I did it not adding without deleting

2º I have a text field where a number will be typed and has to be multiplied in all with the qtd_planned id. It will be of great help to lost in this.

<label for="qtd_planejada" class="col-md-2 control-label">Quantidade planejada:</label>
<div class="col-md-2">
    <form:input path='qtd_planejada' type='text' class="form-control" />
</div>
<form:errors path='qtd_planejada' />

<table id="estruturaTabela" class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th> Item </th>
            <th> Descrição </th>
            <th> Quantidade Base </th>
            <th> Quantidade Planejada </th>
            <th> Disponivel </th>
            <th> Nome da UM </th>
            <th> Depósito </th>
        </tr>
    </thead>
    <tbody id="body">
    </tbody>
</table>

<script>
    $('select[id=produto]').change(function() {
        var itemCode = $(this).val();
        var tbody;
        var tr;
        var tr = document.createElement('TR');
        $.ajax({
            type: "GET",
            url: '/producao/estruturaProduto/' + itemCode,
            success: function(retorno) {
                console.log(retorno);
                if (retorno.length > 0) {
                    //TABLE ROWS
                    tbody = $('#body');
                    for (var i = 0; i < retorno.length; i++) {
                        tr = $('<tr/>').appendTo(tbody);
                        tr.append('<td id="itemcode">' + retorno[i].itemcode + '</td>');
                        tr.append('<td id="itemname">' + retorno[i].itemname + '</td>');
                        tr.append('<td id="qtd_base">' + retorno[i].qtd_base + '</td>');
                        tr.append('<td id="planejada">' + retorno[i].qtd_base + '</td>');
                        tr.append('<td id="disponivel">' + retorno[i].disponivel + '</td>');
                        tr.append('<td id="nomeUM">' + retorno[i].nomeum + '</td>');
                        tr.append('<td id="deposito">' + retorno[i].deposito + '</td>');
                    }
                }
            }
        })
    });
</script>
  • I just didn’t understand about the planned qtd_field, where it is in the code

1 answer

0


Hello, to clear put this code:

$('select[id=produto]').change(function () {
   $('#estruturaTabela tbody').html('') // assim ele limpa o conteúdo da tbody
......
......
});
  • brigado my old was this, had forgotten to put the qtd_planned field, to multiply the by tds I would have to do another function?

  • yes it has to be in separate function, because it is triggered as soon as a certain number is inserted into the field and not when the table is mounted.

  • guess the onblur event helps me with this, but for me to calculate by the q field was inserted by javascript n to viewing this..

Browser other questions tagged

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