Components: [MatPaginator] - Docs about MatPaginatorIntl

Created on 6 Nov 2017  路  3Comments  路  Source: angular/components

Bug, feature request, or proposal:

Feature request.

What is the expected behavior?

I'd expect at least an example showing how to use MatPaginatorIntl and if possible, an example showing, how we (developers) change the labels at runtime (useful for multilingual apps).

What is the current behavior?

There are no examples.

P4 materiapaginator docs good first issue help wanted

Most helpful comment

1.Create a customIntl extends MatPaginatorIntl.You can replace lables of you own.

export class CustomMatPaginatorIntl extends MatPaginatorIntl {
  itemsPerPageLabel = 'number of page'; 
  nextPageLabel     = 'next';
  previousPageLabel = 'previous';

  getRangeLabel = function (page, pageSize, length) {
    if (length === 0 || pageSize === 0) {
      return '0 od ' + 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 startIndex + 1 + ' - ' + endIndex + ' / ' + length;
  };
}

2.add a customIntl to you module where you import the MatPaginator.

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

All 3 comments

1.Create a customIntl extends MatPaginatorIntl.You can replace lables of you own.

export class CustomMatPaginatorIntl extends MatPaginatorIntl {
  itemsPerPageLabel = 'number of page'; 
  nextPageLabel     = 'next';
  previousPageLabel = 'previous';

  getRangeLabel = function (page, pageSize, length) {
    if (length === 0 || pageSize === 0) {
      return '0 od ' + 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 startIndex + 1 + ' - ' + endIndex + ' / ' + length;
  };
}

2.add a customIntl to you module where you import the MatPaginator.

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

Thanks for the example, however I'm asking for it to be documented, so every ppl can access this in https://material.angular.io/paginator. (Also the support for change labels at runtime if possible).

Can this whole thing better be replaced with something better? The solution to create a seperate internationalization file for every component in angular material seems insane for just translating a few strings. Why cant this be exposed as an object property to the normal paginator directive ..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MurhafSousli picture MurhafSousli  路  3Comments

shlomiassaf picture shlomiassaf  路  3Comments

savaryt picture savaryt  路  3Comments

theunreal picture theunreal  路  3Comments

kara picture kara  路  3Comments