Pagination分页

采用分页的形式分隔长列表,每次只加载一个页面。

何时使用

  • 当加载/渲染所有数据将花费很多时间时;
  • 可切换页码浏览数据。
  1. import { NzPaginationModule } from 'ng-zorro-antd/pagination';

代码演示

Pagination分页 - 图1

基本

基础分页。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-basic',
  4. template: `
  5. <nz-pagination [nzPageIndex]="1" [nzTotal]="50"></nz-pagination>
  6. `
  7. })
  8. export class NzDemoPaginationBasicComponent {}

Pagination分页 - 图2

更多

更多分页。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-more',
  4. template: `
  5. <nz-pagination [nzPageIndex]="1" [nzTotal]="500"></nz-pagination>
  6. `
  7. })
  8. export class NzDemoPaginationMoreComponent {}

Pagination分页 - 图3

改变

改变每页显示条目数。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-changer',
  4. template: `
  5. <nz-pagination [nzPageIndex]="3" [nzTotal]="500" nzShowSizeChanger [nzPageSize]="10"></nz-pagination>
  6. <br />
  7. <nz-pagination [nzPageIndex]="3" [nzTotal]="500" nzShowSizeChanger [nzPageSize]="10" nzDisabled></nz-pagination>
  8. `
  9. })
  10. export class NzDemoPaginationChangerComponent {}

Pagination分页 - 图4

跳转

快速跳转到某一页。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-jump',
  4. template: `
  5. <nz-pagination [nzPageIndex]="2" [nzTotal]="500" nzShowQuickJumper></nz-pagination>
  6. <br />
  7. <nz-pagination [nzPageIndex]="2" [nzTotal]="500" nzShowQuickJumper nzDisabled></nz-pagination>
  8. `
  9. })
  10. export class NzDemoPaginationJumpComponent {}

Pagination分页 - 图5

迷你

迷你版本。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-mini',
  4. template: `
  5. <nz-pagination [(nzPageIndex)]="current" [nzTotal]="50" [nzSize]="'small'"></nz-pagination>
  6. <br />
  7. <nz-pagination [(nzPageIndex)]="current" [nzTotal]="50" [nzSize]="'small'" nzShowSizeChanger nzShowQuickJumper></nz-pagination>
  8. <br />
  9. <nz-pagination [(nzPageIndex)]="current" [nzTotal]="50" [nzSize]="'small'" [nzShowTotal]="totalTemplate"></nz-pagination>
  10. <ng-template #totalTemplate let-total>Total {{ total }} items</ng-template>
  11. `
  12. })
  13. export class NzDemoPaginationMiniComponent {
  14. current = 1;
  15. }

Pagination分页 - 图6

简洁

简单的翻页。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-simple',
  4. template: `
  5. <nz-pagination [nzPageIndex]="2" [nzTotal]="50" nzSimple></nz-pagination>
  6. `
  7. })
  8. export class NzDemoPaginationSimpleComponent {}

Pagination分页 - 图7

页码

改变页码。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-controlled',
  4. template: `
  5. <nz-pagination [nzPageIndex]="3" [nzTotal]="50"></nz-pagination>
  6. `
  7. })
  8. export class NzDemoPaginationControlledComponent {}

Pagination分页 - 图8

总数

通过设置 nzShowTotal 展示总共有多少数据。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-total',
  4. template: `
  5. <nz-pagination [nzPageIndex]="1" [nzTotal]="85" [nzPageSize]="20" [nzShowTotal]="totalTemplate"></nz-pagination>
  6. <br />
  7. <nz-pagination [nzPageIndex]="1" [nzTotal]="85" [nzPageSize]="20" [nzShowTotal]="rangeTemplate"></nz-pagination>
  8. <ng-template #totalTemplate let-total> Total {{ total }} items </ng-template>
  9. <ng-template #rangeTemplate let-range="range" let-total> {{ range[0] }}-{{ range[1] }} of {{ total }} items </ng-template>
  10. `
  11. })
  12. export class NzDemoPaginationTotalComponent {}

Pagination分页 - 图9

上一步和下一步

修改上一步和下一步为文字链接。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-pagination-item-render',
  4. template: `
  5. <nz-pagination [nzPageIndex]="1" [nzTotal]="500" [nzItemRender]="renderItemTemplate"></nz-pagination>
  6. <ng-template #renderItemTemplate let-type let-page="page">
  7. <ng-container [ngSwitch]="type">
  8. <a *ngSwitchCase="'page'">{{ page }}</a>
  9. <a *ngSwitchCase="'prev'">Previous</a>
  10. <a *ngSwitchCase="'next'">Next</a>
  11. <a *ngSwitchCase="'prev_5'"><<</a>
  12. <a *ngSwitchCase="'next_5'">>></a>
  13. </ng-container>
  14. </ng-template>
  15. `
  16. })
  17. export class NzDemoPaginationItemRenderComponent {}

API

  1. <nz-pagination [nzPageIndex]="1" [nzTotal]="50"></nz-pagination>

nz-paginationcomponent

参数说明类型默认值
[nzTotal]数据总数number-
[nzPageIndex]当前页数,可双向绑定number1
[nzPageSize]每页条数 ,可双向绑定number10
[nzDisabled]是否禁用booleanfalse
[nzShowQuickJumper]是否可以快速跳转至某页booleanfalse
[nzShowSizeChanger]是否可以改变 nzPageSizebooleanfalse
[nzSimple]当添加该属性时,显示为简单分页boolean-
[nzSize]当为「small」时,是小尺寸分页‘small’‘default’
[nzResponsive]nzSize 未指定时,根据屏幕宽度自动调整尺寸booleanfalse
[nzPageSizeOptions]指定每页可以显示多少条number[][10, 20, 30, 40]
[nzItemRender]用于自定义页码的结构TemplateRef<{ $implicit: ‘page’ | ‘prev’ | ‘next’| ‘prev_5’| ‘next_5’, page: number }>-
[nzShowTotal]用于显示数据总量和当前数据范围,具体使用方式见代码演示部分TemplateRef<{ $implicit: number, range: [ number, number ] }>-
[nzHideOnSinglePage]只有一页时是否隐藏分页器booleanfalse
(nzPageIndexChange)页码改变的回调EventEmitter<number>-
(nzPageSizeChange)每页条数改变的回调EventEmitter<number>-