@@ -19,9 +19,13 @@ import type {
1919 SortParams ,
2020} from './types' ;
2121import { useScrollBasedChunks } from './useScrollBasedChunks' ;
22+ import { calculateElementOffsetTop } from './utils' ;
2223
2324import './PaginatedTable.scss' ;
2425
26+ const HEADER_HEIGHT = 40 ;
27+ const CONTROLS_HEIGHT = 50 ;
28+
2529export interface PaginatedTableProps < T , F > {
2630 limit : number ;
2731 initialEntitiesCount ?: number ;
@@ -57,7 +61,7 @@ export const PaginatedTable = <T, F>({
5761 renderEmptyDataMessage,
5862 containerClassName,
5963} : PaginatedTableProps < T , F > ) => {
60- const initialTotal = initialEntitiesCount || 1 ;
64+ const initialTotal = initialEntitiesCount || 0 ;
6165 const initialFound = initialEntitiesCount || 1 ;
6266
6367 const [ sortParams , setSortParams ] = React . useState < SortParams | undefined > ( initialSortParams ) ;
@@ -75,25 +79,19 @@ export const PaginatedTable = <T, F>({
7579 chunkSize,
7680 } ) ;
7781
78- const handleDataFetched = React . useCallback (
79- ( total : number , found : number ) => {
80- if ( total !== totalEntities ) {
81- setTotalEntities ( total ) ;
82- }
83-
84- if ( found !== foundEntities ) {
85- setFoundEntities ( found ) ;
86- }
87-
88- setIsInitialLoad ( false ) ;
89- } ,
90- [ foundEntities , totalEntities ] ,
91- ) ;
82+ const handleDataFetched = React . useCallback ( ( total : number , found : number ) => {
83+ setTotalEntities ( total ) ;
84+ setFoundEntities ( found ) ;
85+ setIsInitialLoad ( false ) ;
86+ } , [ ] ) ;
9287
9388 // reset table on filters change
9489 React . useLayoutEffect ( ( ) => {
9590 if ( parentRef ?. current && tableRef . current && ! initialTotal ) {
96- parentRef . current . scrollTo ( 0 , tableRef . current . offsetTop ) ;
91+ parentRef . current . scrollTo ( {
92+ left : 0 ,
93+ top : calculateElementOffsetTop ( tableRef . current ) - HEADER_HEIGHT - CONTROLS_HEIGHT ,
94+ } ) ;
9795 }
9896 setTotalEntities ( initialTotal ) ;
9997 setFoundEntities ( initialFound ) ;
0 commit comments