计算Oracle Apex表格单元格的总和

时间:2013-01-22 06:11:04

标签: oracle11g oracle-apex tabular-form

我的oracle apex表格形式中有一列Amount。我需要在输入数据时计算此列下所有字段的SUM,并显示在表格形式下方的Display only字段中。

我认为可以使用JavaScript完成此操作,并在JavaScript列的onchange处调用Amount

但我不知道如何在我的oracle apex表格形式中计算SUM列的Amount。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

将以下JavaScript代码添加到Page HTML Header属性中:

<script type="text/javascript">
function tot_cal()
{
var f5=new Array();
var tol=0;
f5=document.getElementsByName("f05"); /*f05 is Apex array which holds the data*/

 for(i=0;i<f5.length;i++){
  tol = (tol*1) + (f5[i].value.replace(/,/g, '') * 1);
 }
/* alert(tol); */
$s('P10_AMOUNT_VALUE', tol.formatMoney(2,',','.'));
}
Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) {
    var n = this,
    decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
    decSeparator = decSeparator == undefined ? "." : decSeparator,
    thouSeparator = thouSeparator == undefined ? "," : thouSeparator,
    sign = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
    j = (j = i.length) > 3 ? j % 3 : 0;
    return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};
</script>

Amount列的表格形式元素/元素属性属性:

onchange="tot_cal();"