我如何从PrimeNG表中获取当前页面索引

问题描述 投票:0回答:1

我使用 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();
    }
}
angular typescript primeng
1个回答
0
投票

你可以试试这个:

组件.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)"
  >

堆栈闪电战

© www.soinside.com 2019 - 2024. All rights reserved.