• Pagination分页
    • 何时使用
    • 代码演示
    • API
      • 单独引入此组件
      • nz-paginationcomponent

    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. styles: []
    8. })
    9. 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. styles: []
    8. })
    9. 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. `,
    7. styles: []
    8. })
    9. 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. `,
    7. styles: []
    8. })
    9. 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
    8. [(nzPageIndex)]="current"
    9. [nzTotal]="50"
    10. [nzSize]="'small'"
    11. nzShowSizeChanger
    12. nzShowQuickJumper
    13. ></nz-pagination>
    14. <br />
    15. <nz-pagination
    16. [(nzPageIndex)]="current"
    17. [nzTotal]="50"
    18. [nzSize]="'small'"
    19. [nzShowTotal]="totalTemplate"
    20. ></nz-pagination>
    21. <ng-template #totalTemplate let-total>Total {{ total }} items</ng-template>
    22. `,
    23. styles: []
    24. })
    25. export class NzDemoPaginationMiniComponent {
    26. current = 1;
    27. }

    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. styles: []
    8. })
    9. 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. styles: []
    8. })
    9. 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>
    10. {{ range[0] }}-{{ range[1] }} of {{ total }} items
    11. </ng-template>
    12. `,
    13. styles: []
    14. })
    15. export class NzDemoPaginationTotalComponent {}

    Pagination分页 - 图9

    上一步和下一步

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

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

    API

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

    单独引入此组件

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

    1. import { NzPaginationModule } from 'ng-zorro-antd';

    nz-paginationcomponent

    参数说明类型默认值
    [nzTotal]数据总数number-
    [nzPageIndex]当前页数,可双向绑定number1
    [nzPageSize]每页条数 ,可双向绑定number10
    [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>-