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

155
Vistas
Angular Can Not Delete Grid List Element

In my code, I have a grid where the user can enter elements. The user can later on edit or delete the elements he added. The problem is, when I try to delete an element from the middle or the end, the element on the top of the grid gets deleted rather than the one I want. Here is my code. What is wrong with it, and how should I fix it?

HTML:

        <button mat-icon-button>
            <mat-icon (click)="deleteWorkItem(row, i)">block</mat-icon>
        </button>

TS:

dataSource: MatTableDataSource<IMaterialPlanParameter>;
  deleteWorkItem(index: number) {
    let tempData = this.dataSource.data.slice(0);
    tempData.splice(index, 1);
    this.dataSource = new MatTableDataSource(tempData);
    this.EditIndex = undefined;
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this, I use lodash library to clone data,alternatively you can use the variable where you save the data, but it is not clear to me why and what you are passing in the html deleteWorkItem and why you are not calling both elements in the .ts

   deleteWorkItem(row, index) {
    let tempData = clone(this.dataSource.data);
    tempData.splice(index, 1);
    this.dataSource = new MatTableDataSource<IMaterialPlanParameter>(tempData);
  }

If this does not work, I recommend that you create an example with an interactive angular editor.

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