Skip to main content
adicionou 3 caracteres ao conteúdo
Fonte Link
Zuul
  • 35,8mil
  • 21
  • 99
  • 190
var CountMes = 0;

function DataTabela(mesInicial, Diferenca, Ano, pID, pValor) { if (window.location.href.indexOf("compromissoInserir2") > -1) {


function DataTabela(mesInicial, Diferenca, Ano, pID, pValor) {
  if (window.location.href.indexOf("compromissoInserir2") > -1) {

    var Meses = [];
    var IDAtual = 0;

    Meses.push(mesInicial + "/" + Ano);
    while (CountMes < 5 && Diferenca > CountMes) {
        CountMes++;
        mesInicial++;
        if (mesInicial > 12) {
            mesInicial = mesInicial - 12;
            if (Ano < Ano + 1) {
                Ano++;
            }
        }
        Meses.push(mesInicial + "/" + Ano);
    }

    for (var i = 0, l = Meses.length; i < l; i++) {
        $('#NovoCompromisso').find('tr:first').each(function () {
            $(this).append("<th class='text-center'>" + Meses[i] + "</th>");
        });

        if ((l - 1) == i) {
            IDAtual = 0;
        }

        $('#NovoCompromisso').find('tr:not(:first)').each(function () {
            $(this).append("<td ><input type='number' class='p" + pID[IDAtual] + "'   data-id='" + pID[IDAtual] + "' data-preco='" + pValor[IDAtual] + "' /></td>");
            IDAtual++;
        });
    }

    $('#NovoCompromisso').find('tr:first').each(function () {
        $(this).append("<th class='text-center'>Total</th>");
    });
    $('#NovoCompromisso').find('tr:not(:first)').each(function () {
        $(this).append("<td><input type='number' class='totalQTD'  disabled='disabled' value='0' /></td>");
    });

    $('input').on("keyup", function () {
        for (var i = 0, l = pID.length; i < l; i++) {
                sumInputValuesByClass("p" + pID[i]);
        }
    });

 

   }
}

function sumInputValuesByClass(c) {
    var sum = 0;
    $('.' + c).each(function () {
        sum += +$(this).val();
        $(this).parent().parent().find('.totalQTD').val((sum));
    });
}
var CountMes = 0;

function DataTabela(mesInicial, Diferenca, Ano, pID, pValor) { if (window.location.href.indexOf("compromissoInserir2") > -1) {

    var Meses = [];
    var IDAtual = 0;

    Meses.push(mesInicial + "/" + Ano);
    while (CountMes < 5 && Diferenca > CountMes) {
        CountMes++;
        mesInicial++;
        if (mesInicial > 12) {
            mesInicial = mesInicial - 12;
            if (Ano < Ano + 1) {
                Ano++;
            }
        }
        Meses.push(mesInicial + "/" + Ano);
    }

    for (var i = 0, l = Meses.length; i < l; i++) {
        $('#NovoCompromisso').find('tr:first').each(function () {
            $(this).append("<th class='text-center'>" + Meses[i] + "</th>");
        });

        if ((l - 1) == i) {
            IDAtual = 0;
        }

        $('#NovoCompromisso').find('tr:not(:first)').each(function () {
            $(this).append("<td ><input type='number' class='p" + pID[IDAtual] + "'   data-id='" + pID[IDAtual] + "' data-preco='" + pValor[IDAtual] + "' /></td>");
            IDAtual++;
        });
    }

    $('#NovoCompromisso').find('tr:first').each(function () {
        $(this).append("<th class='text-center'>Total</th>");
    });
    $('#NovoCompromisso').find('tr:not(:first)').each(function () {
        $(this).append("<td><input type='number' class='totalQTD'  disabled='disabled' value='0' /></td>");
    });

    $('input').on("keyup", function () {
        for (var i = 0, l = pID.length; i < l; i++) {
                sumInputValuesByClass("p" + pID[i]);
        }
    });

 

   }
}

function sumInputValuesByClass(c) {
    var sum = 0;
    $('.' + c).each(function () {
        sum += +$(this).val();
        $(this).parent().parent().find('.totalQTD').val((sum));
    });
}
var CountMes = 0;

function DataTabela(mesInicial, Diferenca, Ano, pID, pValor) {
  if (window.location.href.indexOf("compromissoInserir2") > -1) {

    var Meses = [];
    var IDAtual = 0;

    Meses.push(mesInicial + "/" + Ano);
    while (CountMes < 5 && Diferenca > CountMes) {
        CountMes++;
        mesInicial++;
        if (mesInicial > 12) {
            mesInicial = mesInicial - 12;
            if (Ano < Ano + 1) {
                Ano++;
            }
        }
        Meses.push(mesInicial + "/" + Ano);
    }

    for (var i = 0, l = Meses.length; i < l; i++) {
        $('#NovoCompromisso').find('tr:first').each(function () {
            $(this).append("<th class='text-center'>" + Meses[i] + "</th>");
        });

        if ((l - 1) == i) {
            IDAtual = 0;
        }

        $('#NovoCompromisso').find('tr:not(:first)').each(function () {
            $(this).append("<td ><input type='number' class='p" + pID[IDAtual] + "'   data-id='" + pID[IDAtual] + "' data-preco='" + pValor[IDAtual] + "' /></td>");
            IDAtual++;
        });
    }

    $('#NovoCompromisso').find('tr:first').each(function () {
        $(this).append("<th class='text-center'>Total</th>");
    });
    $('#NovoCompromisso').find('tr:not(:first)').each(function () {
        $(this).append("<td><input type='number' class='totalQTD'  disabled='disabled' value='0' /></td>");
    });

    $('input').on("keyup", function () {
        for (var i = 0, l = pID.length; i < l; i++) {
                sumInputValuesByClass("p" + pID[i]);
        }
    });

   }
}

function sumInputValuesByClass(c) {
    var sum = 0;
    $('.' + c).each(function () {
        sum += +$(this).val();
        $(this).parent().parent().find('.totalQTD').val((sum));
    });
}
Fonte Link
Rafael Barbosa
  • 2,8mil
  • 1
  • 17
  • 37

Resolvido da seguinte forma

var CountMes = 0;

function DataTabela(mesInicial, Diferenca, Ano, pID, pValor) { if (window.location.href.indexOf("compromissoInserir2") > -1) {

    var Meses = [];
    var IDAtual = 0;

    Meses.push(mesInicial + "/" + Ano);
    while (CountMes < 5 && Diferenca > CountMes) {
        CountMes++;
        mesInicial++;
        if (mesInicial > 12) {
            mesInicial = mesInicial - 12;
            if (Ano < Ano + 1) {
                Ano++;
            }
        }
        Meses.push(mesInicial + "/" + Ano);
    }

    for (var i = 0, l = Meses.length; i < l; i++) {
        $('#NovoCompromisso').find('tr:first').each(function () {
            $(this).append("<th class='text-center'>" + Meses[i] + "</th>");
        });

        if ((l - 1) == i) {
            IDAtual = 0;
        }

        $('#NovoCompromisso').find('tr:not(:first)').each(function () {
            $(this).append("<td ><input type='number' class='p" + pID[IDAtual] + "'   data-id='" + pID[IDAtual] + "' data-preco='" + pValor[IDAtual] + "' /></td>");
            IDAtual++;
        });
    }

    $('#NovoCompromisso').find('tr:first').each(function () {
        $(this).append("<th class='text-center'>Total</th>");
    });
    $('#NovoCompromisso').find('tr:not(:first)').each(function () {
        $(this).append("<td><input type='number' class='totalQTD'  disabled='disabled' value='0' /></td>");
    });

    $('input').on("keyup", function () {
        for (var i = 0, l = pID.length; i < l; i++) {
                sumInputValuesByClass("p" + pID[i]);
        }
    });



   }
}

function sumInputValuesByClass(c) {
    var sum = 0;
    $('.' + c).each(function () {
        sum += +$(this).val();
        $(this).parent().parent().find('.totalQTD').val((sum));
    });
}