Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination on Angular Material Design - Show page numbers or remove the row count

Pagination

Angular 6/7, Material Design.

Since I don't have access to the total number of items the item count is irrelevant (the box in the screen shot).

How do I remove the item count completely? Or alternatively show the page I'm currently on instead of the item count?

<mat-paginator
    itemsPerPageLabel="Items per page"
    (page)="changePage()"
    [length]="resultsLength"
    [pageSizeOptions]="[10, 100]">
</mat-paginator>
like image 338
Johan Faerch Avatar asked Jan 10 '19 08:01

Johan Faerch


People also ask

How do you get the current page number in pagination Angular material?

You can get the current page index by using the page Output event. The $event from page returns three pieces of information: pageIndex. pageSize.

What is Mat-Paginator in Angular?

MatPaginator. Component to provide navigation between paged information. Displays the size of the current page, user-selectable options to change that size, what items are being shown, and navigational button to go to the previous or next page.

What is pagination Angular?

Pagination is a component that only displays page numbers. It will not manipulate your data collection. You will have to split your data collection into pages yourself.


1 Answers

Remove the range label by inserting in global CSS

.mat-paginator-range-label {
    display: none;
}

Insert page number instead (of course based on your API - you might not have the page info!) by inserting in your component

ngAfterViewChecked() {
        const list = document.getElementsByClassName('mat-paginator-range-label');
        list[0].innerHTML = 'Page: ' + this.page.toString();
}

and of course delete the CSS rule above!

Paginator now looks like this

paginator with page indicator instead of range label

like image 65
Johan Faerch Avatar answered Sep 19 '22 15:09

Johan Faerch