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.
Installation
Section titled “Installation”import { RowReorderPlugin } from '@toolbox-web/grid/plugins/reorder-rows';Configuration Options
Section titled “Configuration Options”| Option | Type | Default | Description |
|---|---|---|---|
enableKeyboard | boolean | true | Enable Ctrl+Up/Down shortcuts |
showDragHandle | boolean | true | Show drag handle column |
dragHandlePosition | 'left' | 'right' | 'left' | Drag handle column position |
dragHandleWidth | number | 40 | Drag handle column width |
canMove | function | - | Validation callback |
debounceMs | number | 300 | Debounce time for keyboard moves |
animation | false | 'flip' | 'flip' | Animation for row moves |
Keyboard Shortcuts
Section titled “Keyboard Shortcuts”| Key | Action |
|---|---|
Ctrl + ↑ | Move focused row up |
Ctrl + ↓ | Move focused row down |
Events
Section titled “Events”| Event | Detail | Cancelable | Description |
|---|---|---|---|
row-move | RowMoveDetail | Yes | Fired when a row move is attempted |
Examples
Section titled “Examples”Basic Row Reordering
Section titled “Basic Row Reordering”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);});With Validation
Section titled “With Validation”new RowReorderPlugin({ canMove: (row, fromIndex, toIndex, direction) => { // Prevent moving locked rows return !row.locked; },})See Also
Section titled “See Also”RowReorderConfigfor all configuration optionsRowMoveDetailfor the event detail structure
Extends BaseGridPlugin
Inherited methods like
attach(),detach(),afterRender(), etc. are documented in the base class.
Methods
Section titled “Methods”moveRow()
Section titled “moveRow()”Move a row to a new position programmatically.
moveRow(fromIndex: number, toIndex: number): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
fromIndex | number | Current index of the row |
toIndex | number | Target index |
canMoveRow()
Section titled “canMoveRow()”Check if a row can be moved to a position.
canMoveRow(fromIndex: number, toIndex: number): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
fromIndex | number | Current index of the row |
toIndex | number | Target 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