Pagination分页

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

何时使用#

  • 当加载/渲染所有数据将花费很多时间时;
  • 可切换页码浏览数据。

单独引入此组件#

想要了解更多关于单独引入组件的内容,可以在快速上手页面进行查看。

import { NzPaginationModule } from 'ng-zorro-antd/pagination';

代码演示

基础分页。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-basic',
  template: `
    <nz-pagination [nzPageIndex]="1" [nzTotal]="50"></nz-pagination>
  `
})
export class NzDemoPaginationBasicComponent {}

更多分页。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-more',
  template: `
    <nz-pagination [nzPageIndex]="1" [nzTotal]="500"></nz-pagination>
  `
})
export class NzDemoPaginationMoreComponent {}

改变每页显示条目数。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-changer',
  template: `
    <nz-pagination [nzPageIndex]="3" [nzTotal]="500" nzShowSizeChanger [nzPageSize]="10"></nz-pagination>
    <br />
    <nz-pagination [nzPageIndex]="3" [nzTotal]="500" nzShowSizeChanger [nzPageSize]="10" nzDisabled></nz-pagination>
  `
})
export class NzDemoPaginationChangerComponent {}

快速跳转到某一页。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-jump',
  template: `
    <nz-pagination [nzPageIndex]="2" [nzTotal]="500" nzShowQuickJumper></nz-pagination>
    <br />
    <nz-pagination [nzPageIndex]="2" [nzTotal]="500" nzShowQuickJumper nzDisabled></nz-pagination>
  `
})
export class NzDemoPaginationJumpComponent {}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 10 条/页
    跳至

迷你版本。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-mini',
  template: `
    <nz-pagination [(nzPageIndex)]="current" [nzTotal]="50" [nzSize]="'small'"></nz-pagination>
    <br />
    <nz-pagination
      [(nzPageIndex)]="current"
      [nzTotal]="50"
      [nzSize]="'small'"
      nzShowSizeChanger
      nzShowQuickJumper
    ></nz-pagination>
    <br />
    <nz-pagination
      [(nzPageIndex)]="current"
      [nzTotal]="50"
      [nzSize]="'small'"
      [nzShowTotal]="totalTemplate"
    ></nz-pagination>
    <ng-template #totalTemplate let-total>Total {{ total }} items</ng-template>
  `
})
export class NzDemoPaginationMiniComponent {
  current = 1;
}
  • / 5

简单的翻页。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-simple',
  template: `
    <nz-pagination [nzPageIndex]="2" [nzTotal]="50" nzSimple></nz-pagination>
  `
})
export class NzDemoPaginationSimpleComponent {}

改变页码。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-controlled',
  template: `
    <nz-pagination [nzPageIndex]="3" [nzTotal]="50"></nz-pagination>
  `
})
export class NzDemoPaginationControlledComponent {}

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-total',
  template: `
    <nz-pagination [nzPageIndex]="1" [nzTotal]="85" [nzPageSize]="20" [nzShowTotal]="totalTemplate"></nz-pagination>
    <br />
    <nz-pagination [nzPageIndex]="1" [nzTotal]="85" [nzPageSize]="20" [nzShowTotal]="rangeTemplate"></nz-pagination>
    <ng-template #totalTemplate let-total> Total {{ total }} items </ng-template>
    <ng-template #rangeTemplate let-range="range" let-total>
      {{ range[0] }}-{{ range[1] }} of {{ total }} items
    </ng-template>
  `
})
export class NzDemoPaginationTotalComponent {}

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-pagination-itemRender',
  template: `
    <nz-pagination [nzPageIndex]="1" [nzTotal]="500" [nzItemRender]="renderItemTemplate"></nz-pagination>
    <ng-template #renderItemTemplate let-type let-page="page">
      <a *ngIf="type === 'pre'">Previous</a>
      <a *ngIf="type === 'next'">Next</a>
      <a *ngIf="type === 'page'">{{ page }}</a>
    </ng-template>
  `
})
export class NzDemoPaginationItemRenderComponent {}

API#

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

nz-pagination#

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