gridcn1.2.2

Drag & drop reorder

Reorder one or many rows with the drag handle, the keyboard, or reorderRows - one change, selection follows the rows, one undo step.

Row reorder from three paths: drag a row by its drag handle zone (any reorder-family marker mode: reorder, reorder-number, reorder-checkbox, reorder-both. In the content modes the number and checkbox glyphs stay row-select surfaces, only the drag handle zone reorders, and a press on the drag handle never changes the selection), press Shift+Alt+PageDown or PageUp, or call reorderRows(rows, to) or moveRowsBy(rows, delta) programmatically. Each emits one change with one row-id-based move operation per moved row, so undo/redo restores the previous order in a single step. Selection and the active cell remap by row id, so the rows that were selected stay selected at their new positions, and the dragged row keeps the selected state it had.

New

A drag from a checked row moves every checked row. The rows land together at the drop line.

Row markers
Name
Email
Role
Score
Silent Tiger
user0@example.com
Viewer
4
Quick Lion
user1@example.com
Viewer
89
Swift Wolf
user2@example.com
Manager
80
Eager Lion
user3@example.com
User
51
Eager Tiger
user4@example.com
Viewer
83
Silent Wolf
user5@example.com
User
15
Swift Lion
user6@example.com
Viewer
62
Eager Lion
user7@example.com
Manager
42
Eager Eagle
user8@example.com
Editor
35
Bold Tiger
user9@example.com
Editor
52
Bold Bear
user10@example.com
User
28
Swift Wolf
user11@example.com
Manager
9
Check some rows, then drag one by its drag handle or press Move down — the emitted move operations show up here.
pnpm dlx shadcn@latest add @gridcn/data-grid-row-reorder-demo

What's in the demo

  • rowMarkers="reorder-checkbox": a drag handle and a checkbox in the marker column
  • enableRowReorder on the provider (on by default): the grid-wide switch for the drag gesture
  • A thin line marks the drop target while dragging. The row moves on release
  • Move down toolbar button: moveRowsBy(rows, 1) for the checked rows, or the active row when none is checked - the programmatic path
  • Undo button (the data-grid-history add-on): one click restores the pre-move order
  • The panel prints the last change: the number of move operations, the first operation's rowId and from/to indices, and the change source ("row-operation")

Marker drag vs programmatic

Marker dragreorderRows(rows, to)moveRowsBy(rows, delta)
Inputdrag handle, mouse/touchview indices (to is the final landing position of the first row, arrayMove semantics)view indices and an offset
Rows landtogether, at the drop linetogether, from toeach row moves by delta, gaps stay
Guard checkssame as programmaticsee the no-op guards belowsame as reorderRows
Emitted operationsone move per moved rowone move per moved rowone move per moved row

to is the final position, not an offset: moving row 0 to index 3 shifts rows 1-3 up. The paths are equivalent - use the drag for the interactive UX, the keys for the keyboard, and the actions for buttons or an external "sort by drag" API.

No-op guards

reorderRows returns false (and dev-warns where the cause is a misconfiguration) when:

  • enableRowReorder is off, or the grid is readOnly
  • a sort or filter is active (the view order belongs to the sort/filter, not the data)
  • a lazy grid has unloaded holes (a reorder shifts the lazy add-on's index bookkeeping)
  • the drop leaves the rows where they already are
  • the list is empty, or holds an index outside the grid

See Row operations - Reorder for the full reference, including the stale-position warning for position-based data (search match counts, presence highlights in view-index form).

On this page