Попытка реализовать matSort в Angular 8, но сортировка не определена - PullRequest
0 голосов
/ 19 января 2020

Попытка реализовать сортировку матов по таблице, но сортировка не определена. Я перепробовал все, что мог найти в документации, но ничего не работает. (Удалено ngIf, замените stati c на false, используя все ngAfterViewInit hook без результата)
Я использую [hidden], чтобы скрыть компонент. Любая помощь будет оценена!

--- TS ---

import { Component, ViewChild, Input, AfterViewInit } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { ReportResponse, ReportResponseColumnLabel } from '../../report-response.model';
import { ReportDimension } from '../../report-dimension.enum';

@Component({
  selector: 'app-reporting-table',
  templateUrl: './reporting-table.component.html',
  styleUrls: ['./reporting-table.component.scss'],
})
export class ReportingTableComponent implements AfterViewInit {
  @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  @ViewChild(MatSort, {static: true}) sort: MatSort;

  @Input()
  set reportResult(value: ReportResponse[]) {
    this.setColumns(value);
    this.dataSource.data = value;
  };

  dataSource = new MatTableDataSource<ReportResponse>();
  columns = [];

  ReportResponseColumnLabel = ReportResponseColumnLabel;


  constructor() {
  }


  ngAfterViewInit(): void {
    this.dataSource.paginator = this.paginator;
    this.dataSource.sort = this.sort;
    console.log(this.sort);
  }
}

1 Ответ

1 голос
/ 19 января 2020

Импорт MatSortModule в app.module.ts или material.module.ts (если у вас есть ...)

imports: [
    ....        
    MatSortModule
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...