@angular/material/paginator#PageEvent TypeScript Examples

The following examples show how to use @angular/material/paginator#PageEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pagination.directive.ts    From angular-custom-material-paginator with MIT License 6 votes vote down vote up
constructor(
    @Host() @Self() @Optional() private readonly matPag: MatPaginator,
    private readonly ViewContainer: ViewContainerRef,
    private readonly renderer: Renderer2
  ) {
    this.currentPage = 1;
    this.pageGapTxt = ['•••', '---'];
    this.showTotalPages = 3;
    this.checkPage = [0, 0, 0];
    // Display custom range label text
    this.matPag._intl.getRangeLabel = (page: number, pageSize: number, length: number): string => {
      const startIndex = page * pageSize;
      const endIndex = startIndex < length ?
        Math.min(startIndex + pageSize, length) :
        startIndex + pageSize;
      return length > 0 ? 'Showing ' + (startIndex + 1) + ' – ' + endIndex + ' of ' + length + ' records' : 'Showing 0 – 0 of 0 records';
    };
    // Subscribe to rerender buttons when next page and last page button is used
    this.matPag.page.subscribe((paginator: PageEvent) => {
      this.currentPage = paginator.pageIndex;
      this.matPag.pageIndex = paginator.pageIndex;
      this.initPageRange();
    });
  }
Example #2
Source File: generic-list.component.ts    From Smersh with MIT License 6 votes vote down vote up
onUpdatePaginator(event: PageEvent): void {
    if (this.paginator.itemsPerPage !== event.pageSize) {
      this.paginator.itemsPerPage = event.pageSize;
    }
    if (this.paginator.page !== event.pageIndex + 1) {
      this.paginator.page = event.pageIndex + 1;
    }

    this.filterService.applyFilter({}, (data: Record<string, string>) =>
      this.retrieveData(data)
    );
  }
Example #3
Source File: emote-list.component.ts    From App with MIT License 6 votes vote down vote up
/**
	 * Handle pagination changes
	 */
	onPageEvent(ev: PageEvent): void {
		this.pageOptions = {
			...ev
		};

		if (this.firstPageEvent) {
			this.updateQueryParams(true);
			this.firstPageEvent = false;
		}
		else {
			this.updateQueryParams();
		}

		// Save PageIndex title attr
		this.appService.pushTitleAttributes({ name: 'PageIndex', value: `- ${ev.pageIndex}/${Number((ev.length / ev.pageSize).toFixed(0))}` });

		// Fetch new set of emotes
		this.getEmotes(ev.pageIndex).pipe(
			tap(emotes => this.emotes.next(emotes))
		).subscribe();
	}
Example #4
Source File: ngmat-table-query-reflector.directive.ts    From nghacks with MIT License 6 votes vote down vote up
private listenToStateChangeEvents(): void {
    this.dataSource.sort.sortChange
      .pipe(
        takeUntil(this.unsubscribeAll$)
      )
      .subscribe((sortChange: Sort) => {
        this._applySortChangesToUrlQueryParams(sortChange);
      });

    this.dataSource.paginator.page
      .pipe(
        takeUntil(this.unsubscribeAll$)
      )
      .subscribe((pageChange: PageEvent) => {
        this._applyPageStateChangesToUrlQueryParams(pageChange);
      });
  }
Example #5
Source File: ngmat-table-query-reflector.directive.ts    From nghacks with MIT License 6 votes vote down vote up
private _applyPageStateChangesToUrlQueryParams(pageChange: PageEvent): void {

    const sortingAndPaginationQueryParams = {
      page_size: pageChange.pageSize,
      page_index: pageChange.pageIndex,
    };

    this._router.navigate([], { queryParams: sortingAndPaginationQueryParams, queryParamsHandling: 'merge' });
  }
Example #6
Source File: pager.component.ts    From cli with Apache License 2.0 6 votes vote down vote up
public onPageEvent(event: PageEvent) {
    if (!this.headlessResultPerPage.isSetTo(event.pageSize)) {
      // If page size change
      this.headlessResultPerPage.set(event.pageSize);
      this;
    } else {
      this.headlessPager.selectPage(event.pageIndex + 1);
    }
  }
Example #7
Source File: mat-table.component.ts    From flingo with MIT License 6 votes vote down vote up
handlePageChange(event: PageEvent) {
        if (event.pageSize !== this.currentPageSize) {
            this.staffWebTableService.setPageSize(event.pageSize);

            this.currentPageSize = event.pageSize;

            const numOfPages = this.paginator.getNumberOfPages();

            if (this.currentPageIndex > numOfPages - 1) {
                this.skipToPageFormGroup.patchValue({
                    pageIndex: numOfPages
                });
            }

            this.pageCountArray = this.getPageCountArray(numOfPages);

            this.changeDetectorRef.detectChanges();
        } else if (event.pageIndex !== this.currentPageIndex) {
            this.currentPageIndex = event.pageIndex;

            this.skipToPageFormGroup.patchValue(
                {
                    pageIndex: event.pageIndex + 1
                },
                {
                    emitEvent: false
                }
            );
        }
    }
Example #8
Source File: diet-table.component.ts    From open-genes-frontend with Mozilla Public License 2.0 5 votes vote down vote up
public pageEventHandler(event: PageEvent): void {
    this.pagination.page = event.pageIndex + 1;
    this.pagination.pageSize = event.pageSize;
    this.paginationChange.emit(this.pagination);
  }
Example #9
Source File: entities.component.ts    From open-genes-frontend with Mozilla Public License 2.0 5 votes vote down vote up
public pageEventHandler(event: PageEvent): void {
    const start = event.pageIndex * event.pageSize;
    const end = start + event.pageSize;
    this.list = this.data.slice(start, end);
    this.currentPage = event.pageIndex + 1;
  }
Example #10
Source File: todo2.component.ts    From boot-angular-pagination-example-app with Apache License 2.0 5 votes vote down vote up
nextPage(event: PageEvent) {
    const request = {};
    request['page'] = event.pageIndex.toString();
    request['size'] = event.pageSize.toString();
    this.getTodos(request);
  }
Example #11
Source File: custom-paginator.component.ts    From matx-angular with MIT License 5 votes vote down vote up
// MatPaginator Output
  pageEvent: PageEvent;