-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With traces that have very large tables, if the event table is opened before the trace is fully loaded, the pagination bar does not appear. The problem is that Ag-grid does not make the pagination bar reactive, so it only responds to the initial values of the table. Updates of the number of rows are ignored. The solution is to create a custom pagination bar that can respond reactively to data being loaded. Fixes #849 Signed-off-by: Rodrigo Pinto <rodrigo.pinto@calian.ca>
- Loading branch information
1 parent
e34d2d6
commit d97e257
Showing
4 changed files
with
140 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/react-components/src/components/utils/pagination-bar-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as React from 'react'; | ||
import { GridApi } from 'ag-grid-community'; | ||
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<PaginationBarProps> { | ||
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 <div className='pagination-bar'> | ||
<span style={{ margin: 'auto 10px auto auto'}}> | ||
{firstRow} to {lastRow} of {numberFormat(this.props.nbEvents)} | ||
</span> | ||
|
||
<button className='pagination-button' onClick={() => this.paginationJumpTo(Direction.FIRST)}> | ||
<FontAwesomeIcon icon={faChevronLeft} /> | ||
<FontAwesomeIcon icon={faChevronLeft} /> | ||
</button> | ||
|
||
<button className='pagination-button' onClick={() => this.paginationJumpTo(Direction.PREVIOUS)}> | ||
<FontAwesomeIcon icon={faChevronLeft} /> | ||
</button> | ||
|
||
<span style={{ margin: 'auto 10px' }}> | ||
Page {currentPage} of {this.props.paginationTotalPages + 1} | ||
</span> | ||
|
||
<button className='pagination-button' onClick={() => this.paginationJumpTo(Direction.NEXT)}> | ||
<FontAwesomeIcon icon={faChevronRight} /> | ||
</button> | ||
|
||
<button className='pagination-button' style={{ marginRight: '10px' }} onClick={() => this.paginationJumpTo(Direction.LAST)}> | ||
<FontAwesomeIcon icon={faChevronRight} /> | ||
<FontAwesomeIcon icon={faChevronRight} /> | ||
</button> | ||
</div>; | ||
} | ||
|
||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters