
This is the same screenshot which I shared before, in this when I enter values using tab in all the shop and when I press enter after putting value in shop3 to come to next row, then it is clearing all my data .
I am using following method to enter and calculation the sum: It is working fine, but the thing is my data is getting clear when I press enter to come next row.
onsave(args) {
var columnname; let columnval; var distributionTotal: number = 0;
var dataLength = JSON.stringify(args.rowData).split(",").length;//converted json string into array and getting its length
if (args.column.index == dataLength - 1) {
//this.grid1.refreshColumns();
}
else {
for (var i = 0; i < dataLength; i++) { //assuming that wine name will not have ","
columnname = JSON.stringify(args.rowData).split(",")[i].split(":")[0];
columnval = JSON.stringify(args.rowData).split(",")[i].split(":")[1];
if (i == dataLength - 1) {
columnval = columnval.replace("}", "")//inorder to remove last "}" we use this condition
}
//it will leave the hardcoded initial 4 columns and consoling others dynamic values
if (!((columnname.includes("WineId")) || (columnname.includes("Wine Name")) || (columnname.includes("Brand Total")) || (columnname.includes("Store Total")))) {
if (columnval == "null") {
columnval = 0;
}
var numvalue: number = +columnval; //converting string to number
distributionTotal = distributionTotal + numvalue;
}
}
//Above for loop doesn't consider the value of last change instead considers the previous value.
//To get the correct total we added current value and subtracting the previous value in the following code.
if (args.previousValue === null) {
args.previousValue = 0;
}
distributionTotal = distributionTotal + args.value - +args.previousValue;
// ***Important*** Update store total cell value
this.grid1.setCellValue(args.rowData.WineId, 'Store Total', distributionTotal);
this.storeTotal = distributionTotal;
}
}