Examples › Links or buttons inside clickable rows or cells

Click events bubble up the DOM tree, so when the user clicks on a link, button or other interactive component placed inside a clickable row, clickable cell, expandable row or a row with a context menu triggered by click instead of right-click, the row or cell will react to the click as well.

To prevent this, intercept the click event on the interactive component and call its .stopPropagation() method.

For example, the table below implements both expandable rows and row actions. Clicking on a row expands it, while clicking on an action button only opens a modal dialog, without toggling the row expansion:

Name
City
State
Row actions
Feest, Bogan and HerzogStromanportWY
Cummerata - KuhlmanSouth GateNH
Goyette IncDorthysideID
Runte IncMcAllenMA
Goldner, Rohan and LehnerNorth LouieWY
No records

Here’s the code:

return (
  <DataTable
    striped
    withTableBorder
    withColumnBorders
    records={records}
    columns={[
      { accessor: 'name', noWrap: true },
      { accessor: 'city' },
      { accessor: 'state' },
      {
        accessor: 'actions',
        width: '0%',
        title: <Box mx={6}>Row actions</Box>,
        textAlign: 'right',
        render: (company) => (
          <Group gap={4} justify="right" wrap="nowrap">
            <ActionIcon
              size="sm"
              variant="subtle"
              color="blue"
              onClick={(e: React.MouseEvent) => {
                e.stopPropagation();
                showModal({ company, action: 'edit' });
              }}
            >
              <IconEdit size={16} />
            </ActionIcon>
            <ActionIcon
              size="sm"
              variant="subtle"
              color="red"
              onClick={(e: React.MouseEvent) => {
                e.stopPropagation();
                showModal({ company, action: 'delete' });
              }}
            >
              <IconTrash size={16} />
            </ActionIcon>
          </Group>
        ),
      },
    ]}
    rowExpansion={{
      content: ({ record }) => (
        // ...
      ),
    }}
  />
);

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by