Examples › Asynchronous data loading

When loading data asynchronously, set the fetching property to true while the request is in flight. The DataTable will indicate the loading state by overlaying a Mantine Loader over its rows. Play with the loader properties in the interactive example below:

Name
Street address
City
State
No records

Code:

return (
  <DataTable
    withTableBorder
    minHeight={180}
    columns={[{ accessor: 'name' }, { accessor: 'streetAddress' }, { accessor: 'city' }, { accessor: 'state' }]}
    records={records}
    fetching={fetching}
  />
);

You can customize the loader appearance with the following properties:

  • loaderSize: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | (string & {}) | number
    The loader size. You can also pass a number (in pixels) or any valid CSS size string.
  • loaderType: 'oval' | 'bars' | 'dots'
    The loader type. Defaults to the loader type set in your Mantine theme.
  • loaderColor
    The loader color. Defaults to the theme’s primary color.
  • loaderBackgroundBlur: number
    The loader background blur, in pixels. No blur by default.

If you’re using pagination, the pagination footer will display the loadingText (... by default) while fetching and the total number of records is unknown. The empty state indicator is not displayed while fetching.

return (
  <DataTable
    withTableBorder
    minHeight={180}
    columns={[{ accessor: 'name' }, { accessor: 'streetAddress' }, { accessor: 'city' }, { accessor: 'state' }]}
    records={records}
    fetching={fetching}
    loaderType={customizeLoaderType ? loaderType : undefined}
    loaderSize={customizeLoaderSize ? loaderSize : undefined}
    loaderColor={customizeLoaderColor ? loaderColor : undefined}
    loaderBackgroundBlur={customizeLoaderBackgroundBlur ? loaderBackgroundBlur : undefined}
  />
);

Using a custom loader component

If you’re not happy with the standard Mantine Loader types, you can pass your own component to the customLoader property.
In this case, you can’t set the loaderSize, loaderType and loaderColor properties (TypeScript will complain if you do), but you can still use loaderBackgroundBlur.

Name
Street address
City
State
No records

Here is the code:

return (
  <DataTable
    withTableBorder
    minHeight={180}
    columns={[{ accessor: 'name' }, { accessor: 'streetAddress' }, { accessor: 'city' }, { accessor: 'state' }]}
    records={records}
    fetching={fetching}
    customLoader={
      <svg width={80} height={80} viewBox="0 0 40 40">
        {/* some svg elements... */}
      </svg>
    }
  />
);

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by