Editing Feature Guide
If your tables need full CRUD functionality, you can enable editing features in Mantine React Table.
There are 4 visually distinct editing modes to choose from, whether you want to let users edit data in a modal, inline 1 row at a time, 1 cell at a time, or just always have editing enabled for every cell.
Relevant Table Options
# | Prop Name | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | 'modal' | 'row' | 'custom' | 'modal' | MRT Editing Docs | ||
2 | 'modal' | 'row' | 'cell' | 'table' | 'custom' | 'modal' | MRT Editing Docs | ||
3 | boolean | (row: MRT_Row<TData>) => boolean |
| MRT Editing Docs | ||
4 | ModalProps | ({ row, table }) => ModalProps |
| Mantine Modal Docs | ||
5 | ModalProps | ({ row, table }) => ModalProps |
| Mantine Modal Docs | ||
6 | SelectProps | ({ cell, column, row, table }) => SelectProps |
| Mantine Select Docs | ||
7 | TextInputProps | ({ cell, column, row, table }) => TextInputProps |
| Mantine TextInput Docs | ||
8 | ({ row, table }) => void |
| MRT Editing Docs | ||
9 | OnChangeFn<MRT_Row<TData> | null> |
| |||
10 | ({ exitEditingMode, row, table, values}) => Promise<void> | void |
| MRT Editing Docs | ||
11 | OnChangeFn<MRT_Cell<TData> | null> |
| |||
12 | ({ row, table }) => void |
| MRT Editing Docs | ||
13 | OnChangeFn<MRT_Row<TData> | null> |
| |||
14 | ({ exitEditingMode, row, table, values}) => Promise<void> | void |
| MRT Editing Docs | ||
15 | ({ row, table, internalEditComponents }) => ReactNode |
| |||
16 | ({ row, table, internalEditComponents }) => ReactNode |
| |||
Relevant Column Options
# | Column Option | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | 'select' | 'text' | 'text' | MRT Editing Docs | ||
2 | boolean | (row: MRT_Row<TData>) => boolean |
| |||
3 | SelectProps | ({ cell, column, row, table }) => SelectProps |
| Mantine Select Docs | ||
4 | TextInputProps | ({ cell, column, row, table }) => TextInputProps |
| Mantine TextInput API | ||
Relevant State Options
Enable Editing
To enable editing, first you just need to set the enableEditing
table option to true
.
However, this is just the start. You will need to hook up logic and event listeners, but it depends on which editing mode you want to use.
Editing Modes
Mantine React Table has 4 supported editing modes: "modal"
(default), "row"
, "cell"
and "table"
. You can specify which editing mode you want to use by passing the editDisplayMode
prop.
Modal Editing Mode
The "modal"
editing mode opens up a dialog where the user can edit data for 1 row at a time. No data is saved to the table until the user clicks the save button. Clicking the cancel button clears out any changes that were made on that row.
An onEditingRowSave
callback function prop must be provided where you will get access to the updated row data so that changes can be processed and saved. It is up to you how you handle the data. This function has a exitEditingMode
parameter that must be called in order to exit editing mode upon save. The reason for this is so that you can perform validation checks before letting the modal close.
The
onEditingRowSave
callback function prop includes anexitEditingMode
parameter that must be called in order to exit editing mode upon save. The reason for this is so that you can perform validation checks before letting the modal close.
Actions | First Name | Last Name | Address | City | State |
---|---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky | |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio | |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia | |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska | |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
Row Editing Mode
The row
editing mode is an inline row editing mode. When edit mode is activated, the row shows the edit components in the data cells. No data is saved to the table until the user clicks the save button. Clicking the cancel button clears out any changes that were made on that row.
You must provide an onEditingRowSave
callback function prop where you will get access to the updated row data so that changes can be processed and saved. It is up to you how you handle the data. This function has a exitEditingMode
parameter that must be called in order to exit editing mode upon save. The reason for this is so that you can perform validation checks before letting the modal close.
The
onEditingRowSave
callback function prop includes anexitEditingMode
parameter that must be called in order to exit editing mode upon save. The reason for this is so that you can perform validation checks before letting the modal close.
Actions | First Name | Last Name | Address | City | State |
---|---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky | |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio | |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia | |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska | |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
Cell Editing Mode
The cell
editing mode is a bit simpler visually. Uses double-click cells to activate editing mode, but only for that cell.
Then there is a bit of work for you to do to wire up either the onBlur
, onChange
, etc. events yourself in order to save the table data. This can be done in the mantineEditTextInputProps
table or column option.
First Name | Last Name | Address | City | State |
---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
Table Editing Mode
The table
editing mode is similar to the cell
editing mode, but it simply has all of the data cells in the table become editable all at once.
To save data, you must hook up either the onBlur
, onChange
, etc. events yourself. This can be done in the mantineEditTextInputProps
table or column option.
First Name | Last Name | Address | City | State |
---|---|---|---|---|
Customizing Editing Components
You can customize both the Editing Modal and the Editing Inputs.
Customizing the Editing Modal
You can pass any Mantine Modal Props with the mantineEditRowModalProps
prop.
You can also override all the content of the editing modal by passing a renderEditRowModalContent
prop.
Customizing the Editing Inputs
You can pass any Mantine TextInput Props with the mantineEditTextInputProps
prop.
Add Validation to Editing Components
You can add validation to the editing components by using the mantineEditTextInputProps
events. You can write your validation logic and hook it up to either the onBlur
, onChange
, etc. events, then set the error
and helperText
props accordingly.
If you are implementing validation, you may also need to use the onEditingRowCancel
prop to clear the validation error state.
Use Custom Editing Components
If you need to use a much more complicated Editing component than the built-in textfield, you can specify a custom editing component with the Edit
column definition option.
Customize Actions/Edit Column
You can customize the actions column in a few different ways in the displayColumnDefOptions
prop's 'mrt-row-actions'
section.