1
|
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
|
2
|
import { MatPaginator } from '@angular/material/paginator';
|
3
|
import { MatSort } from '@angular/material/sort';
|
4
|
import { MatTable } from '@angular/material/table';
|
5
|
import { TableDataSource } from './table-datasource';
|
6
|
import { DocumentResponse } from '../../../../model/DocumentResponse';
|
7
|
import { QueryService } from '../../../../services/query/query.service';
|
8
|
|
9
|
@Component({
|
10
|
selector: 'app-table-browse',
|
11
|
templateUrl: './table.component.html',
|
12
|
styleUrls: ['./table.component.css']
|
13
|
})
|
14
|
export class TableComponent implements AfterViewInit, OnInit {
|
15
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
16
|
@ViewChild(MatSort) sort: MatSort;
|
17
|
@ViewChild(MatTable) table: MatTable<DocumentResponse>;
|
18
|
dataSource: TableDataSource;
|
19
|
|
20
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
21
|
displayedColumns = ['id', 'documentName', 'originDate', 'uploadedDate'];
|
22
|
|
23
|
constructor( private queryService: QueryService ) { }
|
24
|
|
25
|
ngOnInit() {
|
26
|
this.dataSource = new TableDataSource();
|
27
|
this.queryService.getDocuments().subscribe( documents => {
|
28
|
this.dataSource.data = documents;
|
29
|
});
|
30
|
}
|
31
|
|
32
|
ngAfterViewInit() {
|
33
|
this.dataSource.sort = this.sort;
|
34
|
this.dataSource.paginator = this.paginator;
|
35
|
this.table.dataSource = this.dataSource;
|
36
|
}
|
37
|
}
|