Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Angular Copying a Row of Table

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;
    
             }
        });   
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to generate an amount of html elements based on the result CopyQuantity of the dialog, I would recommend writing the copies into an array of objects and then using the ngFor directive of Angular to render those elements in the table.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!