Here is my code. In my code, I'm enabling the user to create a row with the same values when he clicks a button next to a row. I want him to be able to create multiple copies. Without the for loop, I can create just one row but, with the for loop, I couldn't manage to create multiple copies. What is missing in my code? What should I do?
copyWorkItem(index: any, row: IWorkItem, event: any) {
const dialogRef = this._dialog.open(CopyDialogComponent, {
width: "550px",
data: row,
});
dialogRef.afterClosed().subscribe((result: IWorkItemSelection) => {
for(let i= 1; i >= result.CopyQuantity; i++){
let item: IWorkItem = {
Product: row.Product,
ProductCategory: row.ProductCategory,
Version: row.Version,
ProductBalance: row.ProductBalance,
DeliveryWarehouse: row.DeliveryWarehouse,
}
if (result.OrderIdCheck == null || result.OrderIdCheck == false) {
item.Order = null;
}
if(result.StockCheck == null || result.StockCheck == false || result.StockCheck == undefined){
item.ProductCategory = null;
item.Product = null;
}
if (result.VersionCheck == null || result.VersionCheck == false) {
item.Version = null;
}
if (result.DeliveryWarehouseCheck == null || result.DeliveryWarehouseCheck == false) {
item.DeliveryWarehouse = null;
}
if (result.QuantityCheck == null || result.QuantityCheck == false) {
item.Quantity = null;
}
//creates a new row
let tempData = this.dataSource.data.splice(0);
tempData.unshift(item);
this.dataSource = new MatTableDataSource(tempData);
this.EditIndex = 0;
}
});
}