Skip to content

Row Reorder Plugin

The Row Reorder plugin lets users rearrange rows by dragging a grip handle or using keyboard shortcuts. Ideal for priority lists, task ordering, or any data where sequence matters.

import '@toolbox-web/grid/features/reorder-rows';

Enable the feature and a drag handle column appears automatically. Users can drag rows to new positions or use Ctrl+Up/Down to move the focused row.

import { queryGrid } from '@toolbox-web/grid';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'priority', header: '#', type: 'number', width: 50 },
{ field: 'task', header: 'Task' },
{ field: 'status', header: 'Status' },
],
features: {
reorderRows: {
dragHandlePosition: 'left',
enableKeyboard: true,
animation: 'flip',
},
},
};
// Listen for row moves
grid.on('row-move', ({ fromIndex, toIndex }) => {
console.log(`Moved row from ${fromIndex} to ${toIndex}`);
// Optionally persist the new order to your backend
});
Handle position Position of drag handle column
Keyboard enabled Allow reorder with keyboard shortcuts
Animation Reorder animation style

Drag the grip handle (☰) to reorder rows. Use Ctrl+Up/Down to move the focused row with the keyboard.

Try moving "Bob" - it will be blocked!

Cancel row moves by calling event.preventDefault() in the row-move handler.

See RowReorderConfig for the full list of options and defaults.

EventDetailCancelableDescription
row-moveRowMoveDetailYesFired when a row move is attempted. Call preventDefault() to block.
KeyAction
Ctrl + ↑Move focused row up
Ctrl + ↓Move focused row down

The plugin adds these CSS classes you can customize:

ClassDescription
.dg-row-drag-handleThe drag handle element
.dg-row-drag-handle:hoverHandle hover state
.data-grid-row.draggingRow currently being dragged
.data-grid-row.drop-targetRow being hovered as drop target
.data-grid-row.drop-beforeDrop indicator showing insertion above
.data-grid-row.drop-afterDrop indicator showing insertion below

Override the default grip icon via CSS:

.dg-row-drag-handle::before {
content: '⋮⋮'; /* Double vertical ellipsis */
}
  • Row Identification: Uses getRowId() from GridConfig if defined, otherwise falls back to array index.
  • Data Mutation: The plugin reorders grid.rows in place. The row-move event provides the updated array.
  • Virtualization: Works with virtualized grids - only visible rows are rendered but logical indices are preserved.
  • Keyboard Debounce: Rapid keyboard moves are debounced (150ms) to prevent excessive rerenders.
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt