I get a list of 100+ users fetched from an api. Now I would like to implement that data in the angular material table.
Is it possible in the frontend that i display only 10 users in pageSize and have pagination. I tried but it displays all available users eventhough I have pagination module implemented.
<mat-paginator [pageSize]="10" showFirstLastButtons></mat-paginator>
In the typescript code, i get the list from the parent component.
import {Component, OnInit, ViewChild, Input, OnChanges} from '@angular/core';
import {MatPaginator, MatTableDataSource} from '@angular/material';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.scss']
})
export class UsersComponent implements OnInit, OnChanges {
@Input() users;
displayedColumns = ['name', 'id'];
dataSource;
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor() { }
ngOnChanges() {
this.dataSource = new MatTableDataSource<any>(this.users);
}
ngOnInit() {
this.dataSource.paginator = this.paginator;
}
}
.ts
file? – mintquanngOnChanges
to get the list of data. – surazzarusngAfterViewInit() { this.dataSource.paginator = this.paginator; }
– Vikas