diff --git a/packages/raystack/table/datatable.tsx b/packages/raystack/table/datatable.tsx index 4cf6eca5..30b5ccdf 100644 --- a/packages/raystack/table/datatable.tsx +++ b/packages/raystack/table/datatable.tsx @@ -108,7 +108,7 @@ function DataTableRoot({ observerRef.current = observer; return () => observer.disconnect(); - }, [onLoadMore]); + }, [onLoadMore, isLoading]); useEffect(() => { const observer = observerRef.current; @@ -140,7 +140,11 @@ function DataTableRoot({ ))} )) - ) + ); + + const tableData = onLoadMore ? data : (isLoading + ? [...new Array(loaderRow)].map((_, i) => ({ id: i } as TData)) + : data); const { filteredColumns, addFilterColumn, removeFilterColumn, resetColumns } = useTableColumn(); @@ -154,7 +158,17 @@ function DataTableRoot({ ? tableCustomFilter[colId] : undefined; - const { cell } = col; + const cell = onLoadMore + ? col.cell + : (isLoading + ? () => ( + + ) + : col.cell); return { ...col, @@ -162,7 +176,7 @@ function DataTableRoot({ filterFn, }; }), - [isLoading, columns, tableCustomFilter] + [isLoading, columns, tableCustomFilter, onLoadMore] ); useEffect(() => { @@ -176,7 +190,7 @@ function DataTableRoot({ }; const table = useReactTable({ - data, + data: tableData, columns: columnWithCustomFilter as unknown as ColumnDef[], globalFilterFn: "auto", enableRowSelection: true, @@ -277,7 +291,7 @@ function DataTableRoot({ }` } ref={ - rowIndex === table.getRowModel().rows.length - 1 + onLoadMore && rowIndex === table.getRowModel().rows.length - 1 ? lastRowRef : null } @@ -305,7 +319,7 @@ function DataTableRoot({ : <> )} - {isLoading && getLoader(loaderRow, columns)} + {isLoading && onLoadMore && getLoader(loaderRow, columns)} {detail}