import * as React from 'react'; import { GridApi } from '@ag-grid-community/core'; import { numberFormat } from './xy-output-component-utils'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faChevronRight } from '@fortawesome/free-solid-svg-icons'; import { faChevronLeft } from '@fortawesome/free-solid-svg-icons'; interface PaginationBarProps { paginationPageSize: number; paginationTotalPages: number; nbEvents: number; gridApi: GridApi | undefined; } enum Direction { NEXT, PREVIOUS, FIRST, LAST } export class PaginationBarComponent extends React.Component { render(): JSX.Element { const currentPage = this.props.gridApi?.paginationGetCurrentPage() ? this.props.gridApi?.paginationGetCurrentPage() + 1 : 1; const firstRowRaw = (currentPage - 1) * this.props.paginationPageSize + 1; const firstRow = numberFormat(firstRowRaw); const lastRow = currentPage === this.props.paginationTotalPages + 1 ? numberFormat(this.props.nbEvents) : numberFormat(firstRowRaw + this.props.paginationPageSize - 1); return (
{firstRow} to {lastRow} of {numberFormat(this.props.nbEvents)} Page {currentPage} of {this.props.paginationTotalPages + 1}
); } private paginationJumpTo(direction: Direction): void { switch (direction) { case Direction.FIRST: this.props.gridApi?.paginationGoToFirstPage(); break; case Direction.LAST: this.props.gridApi?.paginationGoToLastPage(); break; case Direction.NEXT: this.props.gridApi?.paginationGoToNextPage(); break; case Direction.PREVIOUS: this.props.gridApi?.paginationGoToPreviousPage(); break; } this.forceUpdate(); } }