[英]How to achieve this calculation using javascript
First of all thanks for viewing this question.Now,let me show you what I want 首先,感谢您查看此问题。现在,让我告诉您我想要的是什么
as you could see there are two columns in my table.. Now, if someone put 30 or 300 then the table will look like this 如您所见,我的表格中有两列。现在,如果有人输入30或300,则表格将如下所示
Basically,the calculation will go like this way. 基本上,计算将像这样。
Now, I am doing this calculation using javascript and I don't figure out how to get this. 现在,我正在使用javascript进行此计算,但我不知道如何获得此结果。
Here, is my code that I have tried.. 这是我尝试过的代码。
//NOTE: This is an asp grid
//enterdValue = the value I am putting.
function FirstPriority(sender, eventArgs) {
debugger;
var loop = true;
var loopcounter = 0;
if (isNaN($find("<%= txt_payingAmt.ClientID %>").get_textBoxValue())) {
eventArgs.set_cancel(true);
}
else {
let enterdValue = parseFloat($find("<%= txt_payingAmt.ClientID %>").get_textBoxValue());
var grid = $find("<%=rgv_INVList.ClientID%>");
//loop through..
for (var row = 0; row < grid.MasterTableView.get_dataItems().length ; row++) {
var remainingTot = 0;
loopcounter += 1;
var rowTotAmount = parseFloat(grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row], "GrandTotal").innerHTML);
var alreadyPaid = parseFloat(grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row], "PayingAmount").innerHTML);
if (loopcounter == 1) {
if ((alreadyPaid + enterdValue) <= rowTotAmount) {
grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row], "PayingAmount").innerHTML = alreadyPaid + enterdValue;
break;
}
}
else if (loopcounter > 1) {
if ((alreadyPaid + enterdValue) == rowTotAmount) {
grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row], "PayingAmount").innerHTML = rowTotAmount;
break;
}
else {
grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row], "PayingAmount").innerHTML = remainingTot;
break;
}
}
else {
if (loop) {
remainingTot = (alreadyPaid + enterdValue) - rowTotAmount;
grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row], "PayingAmount").innerHTML = rowTotAmount;
if (grid.MasterTableView.get_dataItems().length != loopcounter) {
if (remainingTot <= grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row + 1], "PayingAmount").innerHTML) {
grid.MasterTableView.getCellByColumnUniqueName(grid.MasterTableView.get_dataItems()[row + 1], "PayingAmount").innerHTML = alreadyPaid + enterdValue;
loop = false;
}
}
}
}
}
}
Let me tell you what these variables does, 让我告诉你这些变量的作用
Help needed to achieve this :) Thanks & regards 实现此目标所需的帮助:)谢谢与问候
I have figured out to solve it :) hence posting it here. 我想出解决的方法:)因此,将其发布在这里。
function FirstPriority(args) {
debugger;
resetGrid();
var paidAmount, totAmount, paidAmountHdn, payingAmount, remainingBalance = 0;
payingAmount = parseFloat(args.value);
var grid = $find("<%=rgv_INVList.ClientID%>");
if (!isNaN(payingAmount)) {
remainingBalance = payingAmount;
for (var row = 0; row < grid.MasterTableView.get_dataItems().length ; row++) {
paidAmount = parseFloat(grid.MasterTableView.get_dataItems()[row]._element.cells[5].innerText); //grid.MasterTableView.get_dataItems()[0]._element.cells[1].innerText
totAmount = parseFloat(grid.MasterTableView.get_dataItems()[row]._element.cells[4].innerText);
paidAmountHdn = parseFloat(grid.MasterTableView.get_dataItems()[row]._element.cells[7].innerText);
if (remainingBalance > 0) {
if (row == 0) {
if((paidAmount+payingAmount)>=totAmount)
{
remainingBalance = (paidAmount + payingAmount) - totAmount;
grid.MasterTableView.get_dataItems()[row]._element.cells[5].innerHTML = totAmount;
}
else if ((paidAmount + payingAmount) <= totAmount) {
remainingBalance = 0;
grid.MasterTableView.get_dataItems()[row]._element.cells[5].innerHTML = payingAmount+paidAmount;
break;
}
}
else {
if (remainingBalance > totAmount) {
grid.MasterTableView.get_dataItems()[row]._element.cells[5].innerHTML = totAmount;
remainingBalance = remainingBalance - totAmount;
}
else if(totAmount>=remainingBalance){
grid.MasterTableView.get_dataItems()[row]._element.cells[5].innerHTML = remainingBalance;
remainingBalance = 0;
break;
}
}
}
}
}
else {
for (var row = 0; row < grid.MasterTableView.get_dataItems().length ; row++) {
paidAmountHdn = parseFloat(grid.MasterTableView.get_dataItems()[row]._element.cells[7].innerText);
grid.MasterTableView.get_dataItems()[row]._element.cells[5].innerHTML = paidAmountHdn;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.