Home > other >  how to make click event when i click next or select page size with "mat-paginator " in ang
how to make click event when i click next or select page size with "mat-paginator " in ang

Time:07-23

I am developing a webpage and i have to show list of items with pagination for an api . show when i select a pagesize or click to next page i have to click a method in ts file . but i don't know how to do it . .

html

   <mat-paginator 
    [pageSizeOptions]="[5, 10, 15, 20]"
    [pageSize]="5"
    aria-label="Select page"
    
    ></mat-paginator>

ts file

  searchData:responsebody[] =[];
 dataSource!: MatTableDataSource<any>;
 dataObs$!: Observable<any>;
  ngOnInit(): void {

    this.setPagination();
  
  }

  setPagination() {
    this.dataSource = new MatTableDataSource<any>(this.searchData);
    this._changeDetectorRef.detectChanges();
    this.dataSource.paginator = this.paginator;
    this.dataObs$ = this.dataSource.connect();
  }


//

nextpageData(pagesize:number,index:number){


}

so when i slect page size or click next page i want to call this method "nextpageData(param1,param2)"

enter image description here

CodePudding user response:

mat-paginator has a page event:

Event emitted when the paginator changes the page size or page index.

<mat-paginator (page)="yourHandler($event)"></mat-paginator>
  • Related