Skip to content

Commit 28fa11e

Browse files
author
lharries
committed
handle paginator output
1 parent c6fdd9e commit 28fa11e

File tree

3 files changed

+15
-42
lines changed

3 files changed

+15
-42
lines changed

src/demo-app/table/table-demo.html

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -176,54 +176,17 @@ <h3>MatTable with First/Last Buttons Example</h3>
176176

177177
<div class="demo-table-container demo-mat-table-example mat-elevation-z4">
178178

179-
<table-header-demo (shiftColumns)="displayedColumns.push(displayedColumns.shift())"
180-
(toggleColorColumn)="toggleColorColumn()">
179+
<table-header-demo>
181180
</table-header-demo>
182181

183-
<mat-table [dataSource]="dataSource" [trackBy]="userTrackBy">
184-
185-
<!-- Column Definition: ID -->
186-
<ng-container cdkColumnDef="userId">
187-
<mat-header-cell *matHeaderCellDef> ID </mat-header-cell>
188-
<mat-cell *matCellDef="let row"> {{row.id}} </mat-cell>
189-
</ng-container>
190-
191-
<!-- Column Definition: Progress -->
192-
<ng-container matColumnDef="progress">
193-
<mat-header-cell *matHeaderCellDef> Progress </mat-header-cell>
194-
<mat-cell *matCellDef="let row">
195-
<div class="demo-progress-stat">{{row.progress}}%</div>
196-
<div class="demo-progress-indicator-container">
197-
<div class="demo-progress-indicator"
198-
[style.background]="row.progress > 50 ? 'green' : 'red'"
199-
[style.opacity]="getOpacity(row.progress)"
200-
[style.width.%]="row.progress"></div>
201-
</div>
202-
</mat-cell>
203-
</ng-container>
204-
205-
<!-- Column Definition: Name -->
206-
<ng-container matColumnDef="userName">
207-
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
208-
<mat-cell *matCellDef="let row"> {{row.name}} </mat-cell>
209-
</ng-container>
210-
211-
<!-- Column Definition: Color -->
212-
<ng-container matColumnDef="color">
213-
<mat-header-cell *matHeaderCellDef>Color</mat-header-cell>
214-
<mat-cell *matCellDef="let row" [style.color]="row.color"> {{row.color}} </mat-cell>
215-
</ng-container>
216-
217-
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
218-
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
219-
220-
</mat-table>
182+
<h4 class="paginator-output">{{paginatorOutput | json}}</h4>
221183

222184
<mat-paginator #paginator
223185
[length]="_peopleDatabase.data.length"
224186
[pageSize]="10"
225187
[pageSizeOptions]="[5, 10, 25, 100]"
226-
[showFirstLastButtons]="true">
188+
[showFirstLastButtons]="true"
189+
(page)="handlePaginator($event)">
227190
</mat-paginator>
228191
</div>
229192

src/demo-app/table/table-demo.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,7 @@
141141
background: #f5f5f5;
142142
}
143143
}
144+
145+
.paginator-output {
146+
margin-left: 20px;
147+
}

src/demo-app/table/table-demo.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {Component, ElementRef, ViewChild} from '@angular/core';
1010
import {PeopleDatabase, UserData} from './people-database';
1111
import {PersonDataSource} from './person-data-source';
12-
import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material';
12+
import {MatPaginator, MatSort, MatTableDataSource, PageEvent} from '@angular/material';
1313
import {DetailRow, PersonDetailDataSource} from './person-detail-data-source';
1414
import {animate, state, style, transition, trigger} from '@angular/animations';
1515
import {SelectionModel} from '@angular/cdk/collections';
@@ -65,6 +65,8 @@ export class TableDemo {
6565
@ViewChild('paginatorForDataSource') paginatorForDataSource: MatPaginator;
6666
@ViewChild('sortForDataSource') sortForDataSource: MatSort;
6767

68+
paginatorOutput: PageEvent;
69+
6870
constructor(public _peopleDatabase: PeopleDatabase) {
6971
this.matTableDataSource.sortingDataAccessor = (data: UserData, property: string) => {
7072
switch (property) {
@@ -183,4 +185,8 @@ export class TableDemo {
183185
toggleHighlight(property: string, enable: boolean) {
184186
enable ? this.highlights.add(property) : this.highlights.delete(property);
185187
}
188+
189+
handlePaginator(pageEvent: PageEvent) {
190+
this.paginatorOutput = pageEvent;
191+
}
186192
}

0 commit comments

Comments
 (0)