The simplest way is using slice. You pipe the slice and mention the start index and end index for the part of the data you wish to display. Here is the code:
HTML
<table>
<thead>
...
</thead>
<tbody>
<tr *ngFor="let row of rowData | slice:startIndex:endIndex">
...
</tr>
</tbody>
</table>
<nav *ngIf="rowData" aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item">
<a class="page-link" (click)="updateIndex(0)" aria-label="Previous">
<span aria-hidden="true">First</span>
</a>
</li>
<li *ngFor="let i of getArrayFromNumber(rowData.length)" class="page-item">
<a class="page-link" (click)="updateIndex(i)">{{i+1}}</a></li>
<li class="page-item">
<a class="page-link" (click)="updateIndex(pageNumberArray.length-1)" aria-label="Next">
<span aria-hidden="true">Last</span>
</a>
</li>
</ul>
</nav>
TypeScript
...
public rowData = data // data you want to display in table
public paginationRowCount = 100 //number of records in a page
...
getArrayFromNumber(length) {
if (length % this.paginationRowCount === 0) {
this.pageNumberArray = Array.from(Array(Math.floor(length / this.paginationRowCount)).keys());
} else {
this.pageNumberArray = Array.from(Array(Math.floor(length / this.paginationRowCount) + 1).keys());
}
return this.pageNumberArray;
}
updateIndex(pageIndex) {
this.startIndex = pageIndex * this.paginationRowCount;
if (this.rowData.length > this.startIndex + this.paginationRowCount) {
this.endIndex = this.startIndex + this.paginationRowCount;
} else {
this.endIndex = this.rowData.length;
}
}
Refence for tutorial: https://www.youtube.com/watch?v=Q0jPfb9iyE0