2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AngularMaterialのMatPaginatorを日本語化する

Posted at

CustomPaginatorを作成する

MatPaginatorIntlを継承してCustomPaginatorを作成する。

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

export function CustomPaginator(): any {
  const customPaginatorIntl = new MatPaginatorIntl();

  // Label
  customPaginatorIntl.itemsPerPageLabel = '1 ページあたりの行数: ';
  customPaginatorIntl.getRangeLabel = (page: number, pageSize: number, length: number): string => {
    length = Math.max(length, 0);
    const startIndex = page * pageSize;
    const endIndex = startIndex < length ? Math.min(startIndex + pageSize, length) : startIndex + pageSize;
    return `全 ${length} 件中 ${startIndex + 1}${endIndex} 件目`;
  };
  return customPaginatorIntl;
}

AppModuleでprovideする

作成したCustomPaginatorをapp.module.ts等でprovideする

providers: [
  { provide: MatPaginatorIntl, useValue: CustomPaginator() }
]
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?