I have two columns, Quantity and Pricing. Another column Total which is computed using jQuery functions.
Here's the code for how I'm calculating the Total column:
$('#TableBodyId').on("keyup keypress blur change", "input.proposal-line-pricing, input.proposal-line-quantity", function () {
var result = 1,
$this = $(this).parents('tr');
$this.find('input.proposal-line-pricing, input.proposal-line-quantity').each(function () {
result *= parseFloat(this.value);
});
$this.find("input.proposal-line-total").val(parseFloat(result).toFixed(2));
});
At the footer of the table, is a div which displays the sum of the Total column.
Here's the code for how I'm calculating the sum:
$('#TableBodyId').on("keyup keypress blur change", "input.proposal-line-total", function () {
var $pricings = $("#TableBodyId").find(".proposal-line-total");
var pricingTotal = self.calculateSum($pricings);
$("#PricingTotal strong").html(parseFloat(pricingTotal).toFixed(2));
});
To reflect the change in the footer, I had to trigger something in the total column or it won't change. Right now, I'm doing it like this:
window.setInterval(function () {
$('input.proposal-line-total').trigger("blur")
}, 500);
Is there any other way to not poll the page every 500ms and implement it efficiently? I need it to immediately reflect the change in the div.