Guides
Async Loading UI Guide
How to show loading indicators, skeletons, and progress bars in Shadcn Table
While you are fetching your data, you may want to show some loading indicators. Shadcn Table has some nice loading UI features built in that look better than a simple spinner.
This guide is mostly focused on the loading UI features. Make sure to also check out the Remote Data and React Query examples for server-side logic examples.
Relevant Table Options
Relevant State Options
isLoading UI
There are three different loading UI features that are built into Shadcn Table:
- Loading Overlay - shows spinner overlay over the table container.
- Cell Skeletons - show pretty and shimmering skeletons for each cell.
- Linear Progress Bars - shows progress bars above and/or below the table.
You can use any combination of these loading UIs by managing the showLoadingOverlay, showSkeletons, and showProgressBars states.
There are also two other loading states that are shortcuts for combining some of the above states:
isLoading- shows loading overlay and cell skeletons.isSaving- shows the progress bars and adds spinners to the save buttons in editing features.
Here is some of the recommended loading UI that you might use with React Query:
const {
data = [],
isLoading: isLoadingTodos,
isRefetching: isRefetchingTodos,
} = useQuery({
/**/
});
const { mutate, isPending: isSavingTodos } = useMutation({
/**/
});
const table = useShadcnTable({
columns,
data,
state: {
isLoading: isLoadingTodos, //cell skeletons and loading overlay
showProgressBars: isRefetchingTodos, //progress bars while refetching
isSaving: isSavingTodos, //progress bars and save button spinners
},
});
return <ShadcnTable table={table} />;Note: The Loading Overlay UI makes the table container non-interactive while it is showing. This is usually desired while no data is yet in the table. Consider avoiding using the Loading Overlay UI during "refetching" operations like filtering, sorting, or pagination.
Customize Loading UI
You can customize the loading UI by passing props to the stSkeletonProps, stLinearProgressProps, and stCircularProgressProps props.
const table = useShadcnTable({
columns,
data,
stSkeletonProps: {
className: 'bg-muted/70',
},
stLinearProgressProps: {
progressComponentProps: {
className: '[&>[data-slot=progress-indicator]]:bg-secondary-foreground',
},
},
stCircularProgressProps: {
className: 'text-secondary-foreground',
},
});
return <ShadcnTable table={table} />;Custom Loading Spinner component
If you need to use a custom loading spinner component other than the built-in shadcn/ui one, you can now pass in custom component in the stCircularProgressProps Component prop.
const table = useShadcnTable({
columns,
data,
stCircularProgressProps: {
Component: <MyCustomSpinner />,
},
});Only Show Progress Bars or Skeletons
If you do not want both progress bars and cell skeletons to show, you can use the showProgressBars and showSkeletons states, instead.
const table = useShadcnTable({
columns,
data,
state: {
showProgressBars: true, //or showSkeletons
},
});Full Loading and Server-Side Logic Example
Here is a copy of the full React Query example.