Examples › Row dragging
Mantine DataTable doesn’t include a drag-and-drop implementation of its own, but it exposes the building blocks you need to make rows draggable with a library such as @hello-pangea/dnd (support was added in this PR). Drag a row by its handle to see it in action:
No records
How it works
The implementation relies on the following DataTable features:
tableWrapper→ a function receiving the table aschildrenand returning a React node that wraps it; use it to wrap the table in aDroppablecontainer;rowFactory→ a function that lets you take over the rendering of each row. It receives an object with the currentrecord, itsindex, the defaultrowProps(class name, style, event handlers, etc.), the row cells aschildrenand, if you use row expansion, theexpandedElementto render after the row. Use it to wrap each row in aDraggablecomponent;DataTableDraggableRow→ a table row component exported by Mantine DataTable. Pass it therowPropsreceived byrowFactory, along with anisDraggingflag. While a row is being dragged, the component fixes its cell widths to match the header cells, so that the row keeps its shape, and setsdata-is-dragging="true"on it, which you can use for styling.
Since the drag handle is rendered by rowFactory in an extra cell, you’ll need to add a matching column with hiddenContent set to true, so that the header and body cells stay aligned. Giving the columns explicit widths and setting the table layout to fixed prevents them from changing size while dragging.
Here is the code:
Heads up
Head over to the next example to discover more features.














