Summing up Line item totals and copy to master table total

Tips submitted by PHPMaker users
Post Reply
Niijimasama
User
Posts: 85

Summing up Line item totals and copy to master table total

Post by Niijimasama »

Use this sample to sum up line item totals and copy the value to the totals field on the master table.

Place the code at: Client Scripts->Table Specific->List Page-> Startup Script

function calculateSum() {
	var sum = 0;
	//iterate through each textboxes and add the values
	$("[data-field=x_line_total]").each(function () {// line total field in details field
		//add only if the value is number
		if (!isNaN(this.value) && this.value.length != 0) {
			sum += parseFloat(this.value);
		}
	});
	$("#x_inv_amount").val(sum.toFixed(2));// id of field in master table
}
<?php if(CurrentPageID() == "add"){?>
$("#tbl_detail_tablegrid").on("change", "[data-field=x_field_x]", function () {//activate fxn on change on specific field in detail table
	 calculateSum();
});
<?php }?>

shahparzsoft
User
Posts: 361

Post by shahparzsoft »

I have copied your provided code and paste it exactly where you advised.
But nothing is changing.
Will it sumup the total before saving or after saving ?
and also can u explain this portion [data-field=x_field_x] ?

function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$("[data-field=x1_orderdetails_sitotal]").each(function () {// line total field in details field
//add only if the value is number
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);
}
});
$("#x_orders_sigtotal").val(sum.toFixed(2));// id of field in master table
}
<?php if(CurrentPageID() == "add"){?>
$("#tbl_detail_tablegrid").on("change", "[data-field=x_field_x]", function () {//activate fxn on change on specific field in detail table
calculateSum();
});
<?php }?>


mobhar
User
Posts: 11726

Post by mobhar »

It won't work in v2021. You may read the reason for this post: viewtopic.php?p=158469#p158469


Post Reply