@@ -53,6 +53,8 @@ export interface PageLoadingTableProps<Row, Args>
5353 allItems ?: Row [ ]
5454 callbackToPage ?: ( data : PaginResult < Row > ) => void
5555 allItemsLoadedHint ?: string
56+ emptyDataMsg : string
57+ noSearchResultsMsg : string
5658}
5759
5860const scrollOffset = 350 // Adjust this value for earlier load
@@ -65,6 +67,8 @@ export const PageLoadingTable = function <Row, Args>({
6567 allItems,
6668 callbackToPage,
6769 allItemsLoadedHint = 'All items have been loaded.' ,
70+ emptyDataMsg,
71+ noSearchResultsMsg,
6872 ...props
6973} : PageLoadingTableProps < Row , Args > ) {
7074 const [ page , setPage ] = useState ( 0 )
@@ -79,12 +83,14 @@ export const PageLoadingTable = function <Row, Args>({
7983 } ,
8084 } )
8185 const [ loading , setLoading ] = useState ( true )
86+ const [ noRowsMsg , setNoRowsMsg ] = useState ( '' )
8287
8388 function nextPage ( ) {
8489 setPage ( page + 1 )
8590 }
8691 const hasMore = data ? hasMorePages ( data ) : false
8792 const maxRows = data ? getMaxRows ( data ) : 0
93+ const { searchExpr } = props
8894
8995 useEffect ( ( ) => {
9096 if ( ! allItems ) {
@@ -130,6 +136,16 @@ export const PageLoadingTable = function <Row, Args>({
130136 }
131137 } , [ isSuccess , isFetching , data , clear , loaded ] )
132138
139+ useEffect ( ( ) => {
140+ if ( data ) {
141+ if ( ! searchExpr && data . content . length === 0 ) {
142+ setNoRowsMsg ( emptyDataMsg )
143+ } else if ( searchExpr && data . content . length === 0 ) {
144+ setNoRowsMsg ( noSearchResultsMsg )
145+ }
146+ }
147+ } , [ data , searchExpr ] )
148+
133149 const handleScroll = useCallback ( ( ) => {
134150 const scrollableElement = document . documentElement
135151 if (
@@ -159,6 +175,7 @@ export const PageLoadingTable = function <Row, Args>({
159175 error = { error }
160176 rows = { items }
161177 reload = { refetch }
178+ noRowsMsg = { noRowsMsg }
162179 { ...props }
163180 />
164181 { /* Display loading spinner while fetching data */ }
0 commit comments