Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1e82d716

Přidáno uživatelem Ondřej Váně před asi 4 roky(ů)

Re #7914: Stránkování tabulky browse

- opraveno stránkování tabulky browse
- pořád vypisuje chybu do konzole, ale funguje

Zobrazit rozdíly:

fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts
1
import { Component, OnInit, ViewChild } from '@angular/core';
1
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
2 2
import { MatPaginator } from '@angular/material/paginator';
3 3
import { MatSort } from '@angular/material/sort';
4 4
import { MatTable } from '@angular/material/table';
5 5
import { TableDataSource } from './table-datasource';
6 6
import { DocumentResponse } from '../../../../model/DocumentResponse';
7
import { Observable } from 'rxjs';
8
import { map, tap } from 'rxjs/operators';
9 7
import { QueryService } from '../../../../services/query/query.service';
10 8

  
11 9
@Component({
......
13 11
  templateUrl: './table.component.html',
14 12
  styleUrls: ['./table.component.css']
15 13
})
16
export class TableComponent implements OnInit {
14
export class TableComponent implements AfterViewInit, OnInit {
17 15
  @ViewChild(MatPaginator) paginator: MatPaginator;
18 16
  @ViewChild(MatSort) sort: MatSort;
19 17
  @ViewChild(MatTable) table: MatTable<DocumentResponse>;
20 18
  dataSource: TableDataSource;
21
  dataSourceLength: Observable<number>;
22 19

  
23 20
  /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
24 21
  displayedColumns = ['id', 'documentName', 'originDate', 'uploadedDate'];
......
26 23
  constructor( private queryService: QueryService ) { }
27 24

  
28 25
  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
    );
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;
39 36
  }
40 37
}

Také k dispozici: Unified diff