Skip to content

RowReorderPlugin

Row Reorder Plugin for tbw-grid

Enables row reordering via keyboard shortcuts (Ctrl+Up/Down) and drag-drop. Supports validation callbacks and debounced keyboard moves.

import { RowReorderPlugin } from '@toolbox-web/grid/plugins/reorder-rows';
OptionTypeDefaultDescription
enableKeyboardbooleantrueEnable Ctrl+Up/Down shortcuts
showDragHandlebooleantrueShow drag handle column
dragHandlePosition'left' | 'right''left'Drag handle column position
dragHandleWidthnumber40Drag handle column width
canMovefunction-Validation callback
debounceMsnumber300Debounce time for keyboard moves
animationfalse | 'flip''flip'Animation for row moves
KeyAction
Ctrl + ↑Move focused row up
Ctrl + ↓Move focused row down
EventDetailCancelableDescription
row-moveRowMoveDetailYesFired when a row move is attempted
import { queryGrid } from '@toolbox-web/grid';
import { RowReorderPlugin } from '@toolbox-web/grid/plugins/reorder-rows';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'id', header: 'ID' },
{ field: 'name', header: 'Name' },
],
plugins: [new RowReorderPlugin()],
};
grid.on('row-move', ({ fromIndex, toIndex }) => {
console.log('Row moved from', fromIndex, 'to', toIndex);
});
new RowReorderPlugin({
canMove: (row, fromIndex, toIndex, direction) => {
// Prevent moving locked rows
return !row.locked;
},
})

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Move a row to a new position programmatically.

moveRow(fromIndex: number, toIndex: number): void
NameTypeDescription
fromIndexnumberCurrent index of the row
toIndexnumberTarget index

Check if a row can be moved to a position.

canMoveRow(fromIndex: number, toIndex: number): boolean
NameTypeDescription
fromIndexnumberCurrent index of the row
toIndexnumberTarget index

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