import { AfterViewInit, Component, OnInit, ViewChild, Input } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { MatTable, MatTableDataSource } from '@angular/material/table'; import Folder from '../../folder'; import { SystemConfigService } from '../../services/system-config.service'; @Component({ selector: 'app-folder-list', templateUrl: './folder-list.component.html', styleUrls: ['./folder-list.component.scss'] }) export class FolderListComponent implements AfterViewInit, OnInit { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; @ViewChild(MatTable) table: MatTable; dataSource: MatTableDataSource; applyFilter(event: Event) { const filterValue = (event.target as HTMLInputElement).value; this.dataSource.filter = filterValue.trim().toLowerCase(); } /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ displayedColumns = ['id', 'label']; constructor(private systemConfigService: SystemConfigService) { }; ngOnInit() { this.dataSource = new MatTableDataSource(); this.dataSource.data = []; this.systemConfigService.getFolders().subscribe( data => { this.dataSource.data = data; } ); } ngAfterViewInit() { this.dataSource.sort = this.sort; this.dataSource.paginator = this.paginator; this.table.dataSource = this.dataSource; } }