Currently, I have a table that retrieves data from an API URL, and the data is paginated by default on the server. My goal is to fetch new data when clicking on pages 2
, 3
, etc.
, returning the corresponding page's data from the server.
I am using ant design for my table, but I find their callback methods in the documentation confusing. Therefore, I am seeking assistance to achieve this functionality. Check out the documentation for reference.
Code
Script
listOfData: DataItem[] = []
limit = ''
page = ''
pages = ''
ngOnInit(): void {
this.getList();
}
getList() {
this.helpdeskService.getList().subscribe((res) => {
this.listOfData = res.data;
this.limit = res.limit //10
this.page = res.page //1
this.pages = res.pages //2
if(this.listOfData.length > 0){
this.isSpinning = false;
} else {
this.isSpinning = true;
}
},
(error) => {
console.log('data', error)
});
}
HTML
<ng-template #rangeTemplate let-range="range" let-total>Display {{ range[1] }} of {{ total }} items </ng-template>
<nz-table
#filterTable
nzShowSizeChanger
(nzCurrentPageDataChange)="onCurrentPageDataChange($event)"
[nzData]="listOfData" class="kit__utils__table mb-4"
[nzPageSizeOptions]="[5, 10, 20, 30, 40]"
[nzPageSize]="limit"
[nzPageIndex]="page"
[nzShowTotal]="rangeTemplate">
<thead>
//...
</thead>
<tbody>
..//
</tbody>
</nz-table>
Can anyone assist with implementing this feature?