DocsGuides

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

#
Prop Name
Type
Default Value
More Info Links
1CircularProgressProps | ({ table }) => CircularProgressPropsshadcn/ui CircularProgress Props
2LinearProgressProps | ({ isTopToolbar, table }) => LinearProgressPropsshadcn/ui LinearProgress Props
3SkeletonProps | ({ cell, column, row, table }) => SkeletonPropsshadcn/ui Skeleton Props

Relevant State Options

#
State Option
Type
Default Value
More Info Links
1booleanfalse
2booleanfalse
3booleanfalse
4booleanfalse
5booleanfalse

isLoading UI

There are three different loading UI features that are built into Shadcn Table:

  1. Loading Overlay - shows spinner overlay over the table container.
  2. Cell Skeletons - show pretty and shimmering skeletons for each cell.
  3. 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} />;
Loading example

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
  },
});
Loading example

Full Loading and Server-Side Logic Example

Here is a copy of the full React Query example.

Loading example

On this page