Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda