mardi 2 juillet 2019

Checkbox are not checked when initial values are loaded in a mat-table

Want to load a table with checkbox already checked with the initial values that come from a local storage variable. I already put the initial data in the selectionModel:

this.servChecked = [
    {tipo: 'Servicio', descripcion: 'Visit', cantidad: '1', codsrv: '11123'},
    {tipo: 'Equipo', descripcion: 'RPV', cantidad:'1', codsrv: '11124'}
  ];

this.selection = new SelectionModel<ServiciosAdicionales>(true, this.servChecked);

It does load the array in the selection.selected but the checkboxs are not checked.

TS:

 this.servChecked = JSON.parse(localStorage.getItem("servAdicionales"));
    this.infoCompleta = JSON.parse(localStorage.getItem("infoParaServiciosAdicionales"));
    this.tipoServicio = this.route.snapshot.paramMap.get("tipoServicio");

    let listEquipos = [];
    let listServicios = [];
    this.datosServicios.forEach(element => {
      switch(element.tipo) {
        case '1':
          element.tipo = 'Servicio'
          listServicios.push(element);
          break;
        case '2':
          element.tipo = 'Equipo'
          listEquipos.push(element);
          break;
      }
    });

    this.dataSource = new MatTableDataSource<ServiciosAdicionales>(this.datosServicios);
    this.dataSourceEquipo = new MatTableDataSource<ServiciosAdicionales>(listEquipos);
    this.dataSourceServicio = new MatTableDataSource<ServiciosAdicionales>(listServicios);

    this.selection = new SelectionModel<ServiciosAdicionales>(true, this.servChecked);

I want the checkboxs to be checked when initial values are loaded.




Aucun commentaire:

Enregistrer un commentaire