Skip to content

docs(material/table): use declarative idiomatic RxJS in table-http-example #22053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.example-table-container {
position: relative;
max-height: 400px;
height: 400px;
overflow: auto;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

<div class="example-table-container">

<table mat-table [dataSource]="data" class="example-table"
matSort matSortActive="created" matSortDisableClear matSortDirection="desc">
<table mat-table [dataSource]="filteredAndPagedIssues" class="example-table" matSort
matSortActive="created" matSortDisableClear matSortDirection="desc"
(matSortChange)="resetPaging()">
<!-- Number Column -->
<ng-container matColumnDef="number">
<th mat-header-cell *matHeaderCellDef>#</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {catchError, map, startWith, switchMap} from 'rxjs/operators';
export class TableHttpExample implements AfterViewInit {
displayedColumns: string[] = ['created', 'state', 'number', 'title'];
exampleDatabase: ExampleHttpDatabase | null;
data: GithubIssue[] = [];
filteredAndPagedIssues: Observable<GithubIssue[]>;

resultsLength = 0;
isLoadingResults = true;
Expand All @@ -30,10 +30,7 @@ export class TableHttpExample implements AfterViewInit {
ngAfterViewInit() {
this.exampleDatabase = new ExampleHttpDatabase(this._httpClient);

// If the user changes the sort order, reset back to the first page.
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);

merge(this.sort.sortChange, this.paginator.page)
this.filteredAndPagedIssues = merge(this.sort.sortChange, this.paginator.page)
.pipe(
startWith({}),
switchMap(() => {
Expand All @@ -55,7 +52,11 @@ export class TableHttpExample implements AfterViewInit {
this.isRateLimitReached = true;
return observableOf([]);
})
).subscribe(data => this.data = data);
);
}

resetPaging(): void {
this.paginator.pageIndex = 0;
}
}

Expand Down