States

DataGrid empty state and loading variants

Empty state

Use the emptyState prop of DataGrid to render content when there are no rows to display. The content is rendered in a full-width cell without padding, use the emptyState Styles API selector to style it. The empty state is not displayed while loading is set.

emptyState can be a React node or a function that receives the following object:

interface DataGridEmptyStatePayload<TData extends RowData = any> {
  /** Total rows before filtering. Server-side grids use the rowCount option. */
  rowCount: number;

  /** Number of rows left after filtering. */
  filteredRowCount: number;

  /** Whether a column or global filter is active. */
  isFiltered: boolean;

  /** Table instance, for example to clear filters. */
  table: DataGridTable<TData>;
}
First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
FrankMillerEngineering102000
GraceWilsonMarketing76000
HenryTaylorSales71000
IreneAndersonEngineering97000
JamesThomasFinance91000
KarenJacksonHR63000
LeoWhiteEngineering110000
MiaHarrisSales74000
NathanMartinMarketing69000
OliviaGarciaFinance85000
PatrickMartinezEngineering99000
QuinnRobinsonHR67000
RachelClarkSales73000
import { useState } from 'react';
import { Button, Stack, Switch, Text } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

const noEmployees: typeof employees = [];

function Demo() {
  const [noData, setNoData] = useState(false);

  const store = useDataGrid({
    data: noData ? noEmployees : employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    withGlobalFilter: true,
  });

  return (
    <>
      <Switch
        mb="md"
        label="Simulate an empty data source"
        checked={noData}
        onChange={(event) => setNoData(event.currentTarget.checked)}
      />
      <DataGrid
        store={store}
        emptyState={({ isFiltered, rowCount }) => (
          <Stack align="center" gap="xs" py="xl">
            <Text fw={500}>{isFiltered ? 'No employees match your search' : 'No employees yet'}</Text>
            <Text size="sm" c="dimmed">
              {isFiltered
                ? `Nothing matched in ${rowCount} employees`
                : 'Add an employee to get started'}
            </Text>
            {isFiltered ? (
              <Button size="xs" variant="default" onClick={() => store.setGlobalFilter('')}>
                Clear search
              </Button>
            ) : (
              <Button size="xs">Add employee</Button>
            )}
          </Stack>
        )}
      >
        <DataGrid.Toolbar />
      </DataGrid>
    </>
  );
}

Loading

Set the loading prop on DataGrid to display the loading state:

  • If the grid has no rows yet, skeleton rows are displayed
  • If the grid has rows, the loadingVariant prop defines what is displayed over them
First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
FrankMillerEngineering102000
Loading
import { useState } from 'react';
import { Group, SegmentedControl, Switch } from '@mantine/core';
import { DataGrid, DataGridProps, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [loading, setLoading] = useState(true);
  const [variant, setVariant] = useState<DataGridProps['loadingVariant']>('overlay');

  const store = useDataGrid({
    data: employees.slice(0, 6),
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
  });

  return (
    <>
      <Group mb="md">
        <SegmentedControl
          size="xs"
          data={['overlay', 'bar', 'skeleton']}
          value={variant}
          onChange={(value) => setVariant(value as DataGridProps['loadingVariant'])}
        />
        <Switch
          label="Loading"
          checked={loading}
          onChange={(event) => setLoading(event.currentTarget.checked)}
        />
      </Group>
      <DataGrid store={store} loading={loading} loadingVariant={variant} skeletonRowCount={6} />
    </>
  );
}

Loading variants

VariantRendering
overlay (default)LoadingOverlay over the body, the toolbar, header and footer stay clear. Interaction is blocked while it is visible
barProgress bar under the header, the rows are dimmed and stay interactive. Suits background refreshes and infinite scroll
skeletonSkeleton rows replace the existing rows

The number of skeleton rows is the page size when pagination is enabled and skeletonRowCount (10 by default) otherwise. Use loadingOverlayProps to pass props to LoadingOverlay of the overlay variant:

<DataGrid
  store={store}
  loading={isFetching}
  loadingVariant="overlay"
  loadingOverlayProps={{ loaderProps: { type: 'dots' }, overlayProps: { blur: 0 } }}
/>

<DataGrid store={store} loading={isFetching} loadingVariant="skeleton" skeletonRowCount={5} />

In list view there are no skeleton rows, the skeleton variant displays the overlay instead.

Server-side example

The full server-side example uses loading with loadingVariant="bar": skeleton rows are displayed on the first load and the bar is displayed while a new page, sort or filter is fetched.