Table example.component.ts

Only Added Content
export class TableExampleComponent implements OnInit {

// Initial Content

  resultsLength: number = 0;
  pageSizeOptions: number[] = [5, 25, 50];
  pageIndex?: number = 0;
  pageSize?: number = 5;

  search(): void {
    this.loading = true;
    this.gitHubApiService
      .get(this.query, this.pageIndex, this.pageSize)
      .pipe(take(1))
      .subscribe({
        next: (data) => {
          this.searchResult = data;
          this.resultsLength = data.total_count || 0;
        },
        complete: () => {
          this.loading = false;
        },
      });
  }

  public handlePageEvent(event?: PageEvent): void {
    this.pageIndex = event?.pageIndex;
    this.pageSize = event?.pageSize;

    this.search();
  }

  get showPaginator(): boolean {
    return this.searchResult.items.length > 0 && !this.loading;
  }