Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By ptmi1047
#790908
Hi,

I have a grid with delete row button, and a text field to show total amount from a column in grid.
I do not use grid summary because I need to show the amount with currency format in the field.
How to make the value in text field calculate automatically once I click delete button in grid?


Thank you.
Attachments
2017-05-19_144838.jpg
2017-05-19_144838.jpg (29.52 KiB) Viewed 3688 times
By mishika
#790912
Hello ,

You can use the JS function onDeleteRow() for grids in order to calculate the sum whenever the row is deleted. Please have a look at the function below:
Code: Select all
$("#gridId").onDeleteRow(function(oGrid, aRow, rowIndex) {
   //code for calculation goes here
  var val = parseInt(aRow[0][4].getValue()); //value of deleted row
  var total = parseInt($('#total').getValue()); //get the value of total and subtract the value of deleted row from it
  var sum = total - val;
  $('#total').setValue(sum);
});
Kindly refer to this documentation for more details:
http://wiki.processmaker.com/3.1/JavaSc ... nDeleteRow

You can change the code according to your requirement.

Hope this helps

Best Regards
Mishika
#791027
Hi Mishika,

Thanks for your solution.
I modified the code since the value in grid using currency format.
Code: Select all

$("#OtherExpenses").onDeleteRow(function(oGrid, aRow, rowIndex) {
        
    var Total = 0;
    var Amount = parseFloat(toAngka($('#TotOthExp').getValue())); 
    
    var a1 = aRow[0][4].getValue(); 
    var a2 = a1.replace(",",""); 
    var a = parseInt(a2.replace(",",""));  
    
    var PPN = $('#PPN').getValue();
    
    if (PPN == "0"){
        var TotalOth = Amount - a;
    }
    else {

        var TotalOth = Amount - (a + ((a * 10)/100));

    }
    
    var Summ = toCurr(TotalOth,"");
    
  	 if (isNaN(TotalOth)) { 
      	TotalOth = '';
   	}
   	else { 
      	$('#TotOthExp').setValue(Summ);
    }

  });

Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]