Examples › Empty state

When the records property is an empty array, the DataTable component indicates its empty state by displaying a customizable icon and text, like so:

Name
Email
No records
return (
  <DataTable
    minHeight={150}
    records={[]}
    // ...
  />
);

You can change the displayed text (No records by default) by setting the noRecordsText property:

Name
Email
No records to show
return (
  <DataTable
    minHeight={150}
    records={[]}
    noRecordsText="No records to show"
    // ...
  />
);

You can also replace the icon by setting the noRecordsIcon property:

Name
Email
No records found
return (
  <DataTable
    minHeight={150}
    records={[]}
    noRecordsIcon={
      <Box p={4} mb={4} className={classes.noRecordsBox}>
        <IconMoodSad size={36} strokeWidth={1.5} />
      </Box>
    }
    noRecordsText="No records found"
    // ...
  />
);

If you’re not happy with the standard empty state indicator, you can replace it entirely by setting the emptyState property. The provided content will be overlaid and centered automatically. Note that emptyState and noRecordsIcon are mutually exclusive, and noRecordsText is ignored when emptyState is set:

Name
Email

No data found...

No data found
return (
  <DataTable
    minHeight={280}
    records={[]}
    emptyState={
      <Stack align="center" gap="xs">
        <Text c="dimmed" size="sm">
          No data found...
        </Text>
        <Image
          width={200}
          radius="md"
          src="https://images.unsplash.com/photo-1577460551100-907ba84418ce?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80"
          alt="No data found"
          style={{ filter: 'grayscale(1)' }}
        />
      </Stack>
    }
    // ...
  />
);

Interactive custom empty state content

The empty state overlay has its pointer-events CSS property set to none, so that it doesn’t get in the way of the table underneath.
This means that if you need to add interactive content to a custom empty state, you’ll have to re-enable pointer events on the interactive elements by setting their pointer-events CSS property to all:

Name
Email

No data found...

return (
  <DataTable
    minHeight={280}
    records={[]}
    emptyState={
      <Stack align="center" gap="xs">
        <Text c="dimmed" size="sm">
          No data found...
        </Text>
        <Button
          style={{ pointerEvents: 'all' }} // 👈 enable button pointer events
          onClick={() => notifications.show({ message: 'Should add a new record' })}
        >
          Add a record
        </Button>
      </Stack>
    }
    // ...
  />
);

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by