Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Add Negative Numbers in Interactive Grid and Set to a Page Item with (-) Negative Sign

Dj SteeleOct 9 2019 — edited Nov 11 2019

Good Afternoon Community,

I am using Oracle APEX 5.1.0.00.45 with Google Chrome and PLSQL Developer 12c

I would like to Add Negative Numbers in Interactive Grid ....currently the Grid Works flawlessly with adding Numbers but when I add a ( - ) dash or Negative sign I get NaN when I alert out the Variable.

Here is the Function I'm Using to Loop Through Interactive Grid and Add up what is in the AMOUNT Column and sets the Result to a Page Item on the Page (P234_DTL_AMOUNT)AMOUNT)

Now the End-Users need to enter Negative Amounts for Credits they Receive Back

function addTransActionsDtl() {

var model = apex.region("transdtl").widget().interactiveGrid("getViews", "grid").model;

var EtotalKey = model.getFieldKey("AMOUNT");

var totamt = 0;

model.forEach(function(r,id) {

  var eamt = (r\[EtotalKey\]);

//alert(r[EtotalKey]);

//alert(eamt);

  var eamtnum = parseFloat(eamt.replace(/\\,/g,'')); //.toFixed(2).trim();

alert(eamtnum);

  meta = model.getRecordMetadata(id);

  recId = r\[model.getFieldKey("ROWID")\];

  isDeleted = model.getRecordMetadata(recId).deleted;

  if (typeof(isDeleted) == 'undefined') {

      isDeleted = false

  };

   if (!(isNaN(eamtnum) && !(isDeleted))) {

    totamt += eamtnum;

     alert('After ' + eamtnum);

    }

});

console.log(">> variable totamt is equal to: " + totamt)

//  totamt = totamt.toFixed(2);

// const numberWithCommas = (totamt) => {

//return totamt.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

//}

//model.setValue(record,"REVISED_STATE_AMOUNT", cAmt.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));

 $s('P234\_DTL\_AMOUNT',totamt);

 //model.setValue(record,"P234\_AMOUNT", numberWithCommas(totamt));

}

pastedImage_17.png

Here is the NaN Javascript alert when a dash is entered as first character

pastedImage_19.png

What I would like to see as End Result is for the User to be able to enter Negative Numbers with a Dash ( - ) and Positive Numbers and the Total be Set to the Page Item (P234_DTL_AMOUNT)

Regards

DSteele41

This post has been answered by Natalie G on Oct 11 2019
Jump to Answer
Comments
Post Details
Added on Oct 9 2019
5 comments
1,728 views