apps/mantine.dev/src/pages/core/table.mdx
import { TableDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.Table);
Table data for all examples:
const elements = [
{ position: 6, mass: 12.011, symbol: 'C', name: 'Carbon' },
{ position: 7, mass: 14.007, symbol: 'N', name: 'Nitrogen' },
{ position: 39, mass: 88.906, symbol: 'Y', name: 'Yttrium' },
{ position: 56, mass: 137.33, symbol: 'Ba', name: 'Barium' },
{ position: 58, mass: 140.12, symbol: 'Ce', name: 'Cerium' },
];
You can use the data prop to automatically generate table rows from an array of React nodes.
The data prop accepts an object with the following properties:
head – an array of React nodes (React.ReactNode[]) to render Table.Th in Table.Theadfoot – an array of React nodes (React.ReactNode[]) to render Table.Th in Table.Tfootbody - an array of arrays of React nodes (React.ReactNode[][]) to render Table.Td in Table.Tbodycaption – a React node to render Table.CaptionSet stickyHeader to make the table header sticky. To customize the top position of the header, use the stickyHeaderOffset prop:
it is useful when you have a fixed header in your application. For example, the Mantine documentation website has a fixed
header with 60px height:
To control spacing, use the horizontalSpacing and verticalSpacing props. Both props support spacing from theme.spacing and any valid CSS value to set cell padding:
Table supports tfoot and caption elements. Set the captionSide prop (top or bottom) to change the caption position.
To prevent viewport overflow, wrap Table with Table.ScrollContainer.
The component accepts a minWidth prop which sets the minimum width below which the table will be scrollable.
By default, Table.ScrollContainer uses ScrollArea, you can change it
to native scrollbars by setting type="native":
You can also set the maxHeight prop on Table.ScrollContainer to limit the table height:
Set variant="vertical" to render the table with a vertical layout:
Set the tabularNums prop to render numbers in tabular style. It sets
font-variant-numeric: tabular-nums which makes numbers have equal width.
This is useful when you have columns with numbers and you want them to be aligned: