1
|
import { 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.service';
|
8
|
import {Observable} from 'rxjs';
|
9
|
import {map, tap} from 'rxjs/operators';
|
10
|
|
11
|
@Component({
|
12
|
selector: 'app-table-browse',
|
13
|
templateUrl: './table.component.html',
|
14
|
styleUrls: ['./table.component.css']
|
15
|
})
|
16
|
export class TableComponent implements OnInit {
|
17
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
18
|
@ViewChild(MatSort) sort: MatSort;
|
19
|
@ViewChild(MatTable) table: MatTable<DocumentResponse>;
|
20
|
dataSource: TableDataSource;
|
21
|
dataSourceLength: Observable<number>;
|
22
|
|
23
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
24
|
displayedColumns = ['id', 'documentName', 'originDate', 'uploadedDate'];
|
25
|
|
26
|
constructor( private queryService: QueryService ) { }
|
27
|
|
28
|
ngOnInit() {
|
29
|
this.dataSourceLength = this.queryService.getDocuments().pipe(
|
30
|
tap(data => {
|
31
|
this.dataSource = new TableDataSource();
|
32
|
this.dataSource.data = data;
|
33
|
this.table.dataSource = data;
|
34
|
this.dataSource.sort = this.sort;
|
35
|
this.dataSource.paginator = this.paginator;
|
36
|
}),
|
37
|
map(data => data.length)
|
38
|
);
|
39
|
}
|
40
|
}
|