Как отсортировать несколько мат-таблиц в одном компоненте? - PullRequest
0 голосов
/ 21 октября 2019

Мне нужно отсортировать 2 таблицы в одном компоненте. Пока что никаких результатов, а также ошибок консоли.

TS:

  displayedColumnsAgregados = ['referencia', 'descripcion', 'action']
  dataSourceAgregados = new MatTableDataSource

  displayedColumnsDisponibles = ['referencia', 'inv', 'action']
  dataSourceDisponibles = new MatTableDataSource

  @ViewChild('sortAgregados', {static: false}) sortAgregados: MatSort;
  @ViewChild('sortDisponibles', {static: false}) sortDisponibles: MatSort;

  ngOnInit() {
    this.initForm()
    this.initData()
  }

  ngAfterViewInit() {
    setTimeout(() => {
      this.dataSourceDisponibles.sort = this.sortDisponibles
      this.dataSourceAgregados.sort = this.sortAgregados
    }, 200)
  }

  initData() {
    this.daoUser.getSellers().subscribe( (res:any) => this.userList = res.data)
    this.daoUser.getMechanics().subscribe( (res:any) => this.mechList = res.data)
    this.dao.getAll(this.ITEM_URL).subscribe( res => {
      this.dataSourceDisponibles = res
      this.isLoaded = true
    })
  }

HTML:

        <mat-table [dataSource]="dataSourceAgregados"  #sortAgregados="matSort" matSort matSortDirection="desc" style="background-color: transparent; max-height: 370px;">

          <ng-container matColumnDef="referencia">
            <mat-header-cell *matHeaderCellDef fxFlex="15%" style="justify-content: flex-start" mat-sort-header>Ref.</mat-header-cell>
            <mat-cell *matCellDef="let el" fxFlex="15%" style="justify-content: flex-start">
              {{el.referencia}}
            </mat-cell>
          </ng-container>
..



        <mat-table [dataSource]="dataSourceDisponibles" #sortDisponibles="matSort" matSort matSortDirection="desc" style="background-color: transparent; max-height: 370px;">


          <ng-container matColumnDef="referencia">
            <mat-header-cell *matHeaderCellDef style="justify-content: flex-start" mat-sort-header>Ref.</mat-header-cell>
            <mat-cell *matCellDef="let el" style="justify-content: flex-start">{{el.referencia}}</mat-cell>
          </ng-container>
..

Может кто-нибудь помочь мне решить эти неожиданные, невероятныеИнтересные, острые, соблазнительные и сложные проблемы, пожалуйста?

...