【问题标题】:Angular material table change pagination formatAngular 材质表更改分页格式
【发布时间】:2018-07-10 03:54:45
【问题描述】:

我正在尝试实现一个有角度的材料表。我可以显示带有数据和分页的表格。

但是目前显示的分页格式是下面的格式。

Items per page 10 1- 10 of 20

但我希望分页格式是这样的。

Items per page 10 Range: 10/20

这是plnkr 网址。

【问题讨论】:

标签: angular-material


【解决方案1】:

1.创建一个customIntl extends MatPaginatorIntl。你可以替换你自己的标签。

import { MatPaginatorIntl } from '@angular/material';

export class CustomMatPaginatorIntl extends MatPaginatorIntl {

  getRangeLabel = function (page, pageSize, length) {
    if (length === 0 || pageSize === 0) {
      return '0/' + length;
    }
    length = Math.max(length, 0);
    const startIndex = page * pageSize;
    // If the start index exceeds the list length, do not try and fix the end index to the end.
    const endIndex = startIndex < length ?
      Math.min(startIndex + pageSize, length) :
      startIndex + pageSize;
    return endIndex + ' / ' + length;
  };
}

2.向您导入 MatPaginator 的模块添加 customIntl。

imports: [
       ...
       MatPaginatorModule,
],
providers: [
     ...
    {provide: MatPaginatorIntl, useClass: CustomMatPaginatorIntl}
  ]

【讨论】:

    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 2017-09-30
    • 2018-07-06
    • 2016-12-08
    • 1970-01-01
    • 2021-11-04
    • 2018-06-17
    • 1970-01-01
    相关资源
    最近更新 更多