我使用 PrimeNg 库和启用了分页器的
Table
组件。 Django 后端应用程序使用 PageNumberPagination
。如何从该组件获取当前页码?
<p-table
[value]="rows"
[paginator]="true"
[rows]="10"
></p-table>
@Component({
selector: 'app-table',
templateUrl: 'table.html',
standalone: true,
imports: [TableModule, CommonModule],
providers: [ApiService]
})
export class TablePaginatorBasicDemo {
rows!: Row[];
constructor(private apiService: ApiService) {}
ngOnInit() {
this.apiService.getRows().pipe(tap((rows) => ({this.rows = rows}))).subscribe();
}
}
你可以试试这个:
组件.ts:
readonly ROWS_PER_PAGE = 5;
currentPage = 0;
updateCurrentPage(first: number): void {
this.currentPage = first / this.ROWS_PER_PAGE;
console.log('current page changed to: ', this.currentPage + 1);
}
component.template.html:
<p-table
responsiveLayout="scroll"
[value]="products"
[paginator]="true"
[rows]="ROWS_PER_PAGE"
(firstChange)="updateCurrentPage($event)"
>