Examples › Column dragging and toggling
Mantine DataTable lets users reorder columns by drag-and-drop and show or hide them as needed. The column order and visibility are persisted in the browser’s local storage, so they survive page reloads. These features were originally contributed by Giovambattista Fazioli — thanks for the outstanding work!
Column drag-and-drop reordering
In order to enable column dragging you’ll have to:
- add a
storeColumnsKey: 'your_key'property to the DataTable (the column order is persisted in local storage under this key); - add a
draggable: trueproperty to each dragging candidate column; - use the
useDataTableColumns()hook with the samekeyto get the effective (sorted) columns and pass them to the DataTable.
Draggable columns display a grip icon in their header. A column can only be dropped onto another draggable column, and is then moved to that column’s position.
Column toggling
In the example below:
- you can toggle the first 3 columns;
- the last column is not toggleable and will always be visible;
- the first column is hidden by default.
Hover over a toggleable column header and click its × button to hide the column, or right-click anywhere on the table header to open a menu where you can show or hide each toggleable column.
In order to enable column toggling you’ll have to:
- add a
storeColumnsKey: 'your_key'property to the DataTable (the column visibility is persisted in local storage under this key); - add a
toggleable: trueproperty to each toggling candidate column; - use the
useDataTableColumns()hook with the samekeyto get the effective columns and pass them to the DataTable.
Custom column visibility controls
Besides the built-in header menu, you can build your own column visibility controls. The useDataTableColumns() hook returns the current visibility state as columnsToggle — an array of { accessor, toggleable, toggled } objects — and a setColumnsToggle() function to update it:
Adding and removing columns at runtime
You can add or remove columns at runtime by simply changing the array of columns you pass to the hook. The persisted order and visibility state is automatically kept in sync with the current column definitions: state for removed columns is discarded, and newly added columns are appended with their default settings.
Resetting the column state from a context menu
The reset functions returned by the hook can be called from anywhere — for example, from a row context menu. Right-click on any row in the example below to reset the column visibility or order:
Combining dragging and toggling with sorting
Column dragging and toggling work seamlessly with other features, such as sorting:
See also column resizing and pinning arbitrary columns, which rely on the same hook.














