Theme

Examples › Row context menu

Mantine doesn’t have a context-menu component, but the DataTable does allow you to create this useful functionality for your data-rich desktop applications by providing a property called rowContextMenu to describe the menu actions and behavior.
Try it in the interactive example below:
Sipes Inc280 Rigoberto DivideTwin FallsMT
Runolfsdottir - Cummerata102 Konopelski GreensMissouri CityKY
Johnston LLC230 Julie LakeHartfordKY
Crist and Sons3387 Blick TurnpikeAttleboroWV
Schmidt and Sons286 Leif LockColliervilleAL
Nicolas Group09622 Marcel PlaceHighlandOR
Kub and Sons8699 Upton FordsEast ProvidenceIN
Jakubowski - Rolfson191 O'Connell GreensSan RafaelMA
Welch - Tremblay31622 Isobel FallOlatheAR
Mueller, Hodkiewicz and Beahan21751 Elisa VillageGrand PrairieWA
No records
<DataTable
withBorder
columns={[{ accessor: 'name' }, { accessor: 'streetAddress' }, { accessor: 'city' }, { accessor: 'state' }]}
records={companies}
rowContextMenu={{
items: (record) => [
{
key: 'edit',
onClick: () => showNotification({ message: `Should edit company ${record.name}` }),
},
{
key: 'delete',
color: 'red',
title: `Delete company ${record.name}`,
onClick: () => showNotification({ color: 'red', message: `Should delete company ${record.name}` }),
},
{
key: 'sendMessage',
title: 'Send message to company HQ',
onClick: () => {
showNotification({ message: 'Should send a message to this company' });
},
},
],
}}
/>

Using row context menus inside modals

When using row context menus on data tables inside modals, you need to make sure that the context menu is rendered above the modal. To do so, you need to set its zIndex property to a value higher than the modal’s zIndex:
<Button
leftIcon={<IconAppWindow size={16} />}
onClick={() =>
modals.open({
title: 'Right-click on a row',
children: (
<DataTable
height={300}
withBorder
borderRadius="sm"
columns={[
{ accessor: 'name', title: 'Company name' },
{ accessor: 'city', textAlignment: 'right' },
]}
records={companies}
rowContextMenu={{
zIndex: 202, // 👈 make sure the context menu is above the modal
// items...
/>
),
})
}
>
Open modal
</Button>
If you’re not a fan of context menus, implementing a row actions cell should’t be difficult.

Mantine DataTable is trusted by

MIT LicenseSponsor the author
Built by Ionut-Cristian Florescu and these awesome people.
Please sponsor the project if you find it useful.
GitHub StarsNPM Downloads