Adding values from a td column

0

I would like to know how to calculate the values of a column and play in a field. They are automatically loaded

Thisisthehtmlofthetable.Iwanttoaddthevaluesinthevalue_postercolumnandplayintheqtdtotalfieldjustbelow.

<tableclass="table table-md-striped table-condensed" id="tblImpostos" tablename="tblImpostos" noaddbutton="true" nodeletebutton="true">
    <thead>
        <tr>
            <th>Ano Competência</th>
            <th>Mês Competência</th>
            <th>Desconto</th>
            <th>Valor</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <input readonly type="text" class="form-control input-sm" name="anocompetenciaimpostos" id="anocompetenciaimpostos">
            </td>
            <td>
                <input readonly type="text" class="form-control input-sm" name="mescompetenciaimpostos" id="mescompetenciaimpostos">
            </td>

            <td>
                <input readonly type="text" class="form-control input-sm" name="descontoimpostos" id="descontoimpostos">
            </td>
            <td>
                <input readonly type="text" class="form-control input-sm valor-calculado" name="valorimpostos" id="valorimpostos">
            </td>

        </tr>
    </tbody>
</table>

<input readonly type="text" class="form-control input-sm" name="qtdtotal" id="qtdtotal">

This is the javascript that loads the data into the table

function getImpostos(){

    if ($("#nmQtdListaImpostos").val() == "0"){
        var chapafuncionario = $('#chapafuncionario').val();
        var anoreferencia = $('#anoreferencia').val();
        var mesreferencia = $('#mesreferencia').val();
        var c1 = DatasetFactory.createConstraint("chapa", chapafuncionario, chapafuncionario, ConstraintType.MUST);
        var c2 = DatasetFactory.createConstraint("anocomp", anoreferencia, anoreferencia, ConstraintType.MUST);
        var c3 = DatasetFactory.createConstraint("mescomp", mesreferencia, mesreferencia, ConstraintType.MUST);
        var constraints   = new Array(c1, c2, c3);
        var dataset = DatasetFactory.getDataset("dsImpostos", null, constraints, null);

        for(var i = 0; i < dataset.values.length; i++) {
            row = dataset.values[i];
            linha = wdkAddChild('tblImpostos');

            $("#nmQtdListaImpostos").val(linha);

            $("#anocompetenciaimpostos___" + linha).val(row["ANOCOMP"]);
            $("#mescompetenciaimpostos___" + linha).val(row["MESCOMP"]);
            $("#descontoimpostos___" + linha).val(row["DESCRICAO"]);
            $("#valorimpostos___" + linha).val(row["VALOR"]);
        }   
    }
}
    
asked by anonymous 30.10.2018 / 12:34

2 answers

1

You can add these values as you fill in the table, and soon after displaying this result

var total = 0;
for(var i = 0; i < dataset.values.length; i++) {
    row = dataset.values[i];
    linha = wdkAddChild('tblImpostos');
    $("#nmQtdListaImpostos").val(linha);

    $("#anocompetenciaimpostos___"+linha).val(row["ANOCOMP"]);
    $("#mescompetenciaimpostos___"+linha).val(row["MESCOMP"]);
    $("#descontoimpostos___"+linha).val(row["DESCRICAO"]);
    $("#valorimpostos___"+linha).val(row["VALOR"]);

    total += row["VALOR"];
}   
$("#qtdtotal").val(total);
    
30.10.2018 / 12:46
0

Hello! follow the function below, just put it on your page and call when you want, it should work!

function calculaFinal(){
    var valorFinal = 0;
    //pega todos os campos de imposto dentro da table
    $("#tblImpostos input[name*='valorimpostos']").toArray().forEach(function(element,index){
        valorFinal += parseInt(element.value);
    })
    //aplica no valor final
    $('#qtdtotal').val(valorFinal)
}

If you solve your problem, do not forget to mark the correct answer as this helps others with the same problem!

    
01.11.2018 / 14:24