Paulolafoudre
Paulolafoudre

Reputation: 97

Is there an EventListener on mat-paginator last or first button?

I need to listen when I especially click on mat-paginator last-button. Is there an event listener or a way to do this ?

I tried : (page)="pageEvent = $event;emitPagination($event)" but it does not return information about where I clicked.

and same for (click) = event($event)

HTML :

<mat-paginator #paginator 
    [length]="totalElements" 
    [pageSize]="5" 
    [showFirstLastButtons]="true" 
    (page)="pageEvent = $event;emitPagination($event)">
</mat-paginator>

I expect to call a specific method when last button is clicked.

Upvotes: 7

Views: 7000

Answers (1)

Nenad Radak
Nenad Radak

Reputation: 3678

MatPaginator have method lastPage you can trigger it from ts file like in this example:

@ViewChild(MatPaginator) paginator: MatPaginator;

 ngAfterViewInit() {
  this.paginator.lastPage = () => this.yourMethodToTrigger();
 }

 yourMethodToTrigger(){
 console.log('Triggered!')
 }

Also can read from official documentation in section methods https://material.angular.io/components/paginator/api

Upvotes: 2

Related Questions