Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda