Row DnD Ordering Example
Material React Table has built-in support for row drag and drop re-ordering. Learn more about column ordering in the Row Ordering Feature Guide.
Move | First Name | Last Name | City |
---|---|---|---|
Dylan | Murray | East Daphne | |
Raquel | Kohler | Columbus | |
Ervin | Reinger | South Linda | |
Brittany | McCullough | Lincoln | |
Branson | Frami | Charleston |
10
1-5 of 5
1import { useMemo, useState } from 'react';2import {3 MaterialReactTable,4 type MRT_ColumnDef,5 type MRT_Row,6} from 'material-react-table';7import { data as initData, type Person } from './makeData';89const Example = () => {10 const columns = useMemo<MRT_ColumnDef<Person>[]>(11 //column definitions...28 );2930 const [data, setData] = useState(() => initData);3132 return (33 <MaterialReactTable34 autoResetPageIndex={false}35 columns={columns}36 data={data}37 enableRowOrdering38 enableSorting={false}39 muiRowDragHandleProps={({ table }) => ({40 onDragEnd: () => {41 const { draggingRow, hoveredRow } = table.getState();42 if (hoveredRow && draggingRow) {43 data.splice(44 (hoveredRow as MRT_Row<Person>).index,45 0,46 data.splice(draggingRow.index, 1)[0],47 );48 setData([...data]);49 }50 },51 })}52 />53 );54};5556export default Example;57
View Extra Storybook Examples