Column Ordering (DnD) Feature Guide
Whether you just want to change the default column order in your table or let columns be reordered by dragging and dropping, Mantine React Table has a simple API for this.
Relevant Table Options
# | Prop Name | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | boolean | false | MRT Column Ordering DnD Docs | ||
2 | boolean |
| MRT Column Ordering DnD Docs | ||
3 | OnChangeFn<ColumnOrderState> |
| TanStack Table Column Ordering Docs | ||
4 | OnChangeFn<MRT_Column<TData> | null> |
| |||
5 | OnChangeFn<MRT_Column<TData> | null> |
| |||
Relevant Column Options
Relevant State
# | State Option | Type | Default Value | More Info Links | |
---|---|---|---|---|---|
1 | Array<string> | [] | TanStack Table Column Ordering Docs | ||
2 | MRT_Column | null |
| |||
3 | MRT_Column | null |
| |||
Change the Default Column Order
By Default, Mantine React Table will order the columns in the order they are defined in the columns
definition. And Display Columns such as Actions, Selection, Expansion, etc., get added to either the beginning or the end of the table. You can customize all of this by defining your own columnOrder
State and passing it either to the initialState
or state
props.
The Column Order State is an array of string column ids, that come from the ids or accessorKeys that you defined in your column definitions.
Manage Column Order State
If you need to manage the columnOrder
state yourself, you can do so in the state
table option and onColumnOrderChange
callback, but you will also need to initialize the columnOrder
state yourself.
Enable Column Ordering with Drag and Drop
Mantine React Table has a built-in drag and drop feature to reorder columns. This feature is enabled by passing the enableColumnOrdering
table option.
The ability for a column to have a drag and drop handle can be specified by setting the enableColumnOrdering
option on the column.
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 |
View Extra Storybook Examples
Note: Drag and Drop is not currently supported on mobile touch devices.