I am using Angular 6.0.3 with Angular Material 7.1.0, I have my paginator in a separate component (that is not the app.component). What I have tried so far:
Created separate ts file called myPagniator.ts:
import {MatPaginatorIntl} from '@angular/material';
export class MyPaginatorLabel extends MatPaginatorIntl {
itemsPerPageLabel = 'custome_label_name'; // customize item per page label
constructor() {
super();
}
}
In my app.module.ts : I imported both MatPaginatorModule, MatPaginatorIntl from Angular Material. Inside providers array of app.module.ts, I put in MyPaginatorLabel and MatPaginatorIntl.
In the component which is using Angular MatPaginator, I extends MyPaginatorLabel class and have its constructor calls super() method, still it displays default text "itemsPerPage" after all this
What have I done wrong here ?? Can someone give me a bit of hint ?
Create subclass of MatPaginatorIntl in which you inject TranslateService. In the constructor translate the paginator labels and listen for language changes to trigger the same. The rangeLabel is translated with interpolation of the startIndex, endIndex and length variables. Save this answer.
How to hide Pagination in Angular Material Datatable if there is no row? For this, we will simply add the [hidden] directive of Angular to show/ hide the element based on the boolean value provided. The [hidden] simply adds hidden attribute with style set to display:none if you are using bootstrap. css.
The paginator displays a dropdown of page sizes for the user to choose from. The options for this dropdown can be set via pageSizeOptions. The current pageSize will always appear in the dropdown, even if it is not included in pageSizeOptions.
Create a new TypeScript file and add a function that is exported and returns a MatPaginatorIntl
object.
To modify the labels and text displayed, create a new instance of MatPaginatorIntl and include it in a custom provider - Angular Material - Paginator > API
CustomPaginatorConfiguration.ts
import { MatPaginatorIntl } from '@angular/material';
export function CustomPaginator() {
const customPaginatorIntl = new MatPaginatorIntl();
customPaginatorIntl.itemsPerPageLabel = 'Custom_Label:';
return customPaginatorIntl;
}
Then add it to app.module.ts
:
import { MatPaginatorIntl } from '@angular/material';
import { CustomPaginator } from './app/CustomPaginatorConfiguration';
@NgModule({
// ...
providers: [
{ provide: MatPaginatorIntl, useValue: CustomPaginator() }
]
})
You can also set the setting for a particular component like:
import { CustomPaginator } from './CustomPaginator';
import { MatPaginatorIntl } from '@angular/material';
/**
* @title Paginator
*/
@Component({
selector: 'your_component',
templateUrl: 'your_component.html',
providers: [
{ provide: MatPaginatorIntl, useValue: CustomPaginator() } // Here
]
})
StackBlitz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With