ReorderPlugin
Column Reorder Plugin for tbw-grid
Lets users rearrange columns by dragging and dropping column headers. Supports smooth
FLIP animations, fade transitions, or instant reordering. Animation respects the
grid-level animation.mode setting.
Installation
Section titled “Installation”import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder-columns';Configuration Options
Section titled “Configuration Options”| Option | Type | Default | Description |
|---|---|---|---|
animation | false | 'flip' | 'fade' | 'flip' | Animation type for column moves |
animationDuration | number | 200 | Animation duration in ms |
Keyboard Shortcuts
Section titled “Keyboard Shortcuts”| Key | Action |
|---|---|
Alt + ← | Move focused column left |
Alt + → | Move focused column right |
Events
Section titled “Events”| Event | Detail | Cancelable | Description |
|---|---|---|---|
column-move | { field, fromIndex, toIndex, columnOrder } | Yes | Fired when a column move is attempted |
Examples
Section titled “Examples”Basic Drag-and-Drop Reordering
Section titled “Basic Drag-and-Drop Reordering”import { queryGrid } from '@toolbox-web/grid';import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder-columns';
const grid = queryGrid('tbw-grid');grid.gridConfig = { columns: [ { field: 'id', header: 'ID' }, { field: 'name', header: 'Name' }, { field: 'email', header: 'Email' }, ], plugins: [new ReorderPlugin({ animation: 'flip', animationDuration: 200 })],};
// Persist column ordergrid.on('column-move', ({ columnOrder }) => { localStorage.setItem('columnOrder', JSON.stringify(columnOrder));});Prevent Moves That Break Group Boundaries
Section titled “Prevent Moves That Break Group Boundaries”grid.on('column-move', (detail, e) => { if (!isValidMoveWithinGroup(detail.field, detail.fromIndex, detail.toIndex)) { e.preventDefault(); // Column snaps back to original position }});See Also
Section titled “See Also”ReorderConfigfor all configuration optionsColumnMoveDetailfor the event detail structureGroupingColumnsPluginfor column group integration
Extends BaseGridPlugin
Inherited methods like
attach(),detach(),afterRender(), etc. are documented in the base class.
Accessors
Section titled “Accessors”animationDuration
Section titled “animationDuration”Get animation duration, allowing plugin config override. Uses base class animationDuration for default.
readonly animationDuration: numberMethods
Section titled “Methods”getColumnOrder()
Section titled “getColumnOrder()”Get the current column order from the grid.
getColumnOrder(): string[]Returns
Section titled “Returns”string[] - Array of field names in display order
moveColumn()
Section titled “moveColumn()”Move a column to a new position.
moveColumn(field: string, toIndex: number): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
field | string | The field name of the column to move |
toIndex | number | The target index |
setColumnOrder()
Section titled “setColumnOrder()”Set a specific column order.
setColumnOrder(order: string[]): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
order | string[] | Array of field names in desired order |
resetColumnOrder()
Section titled “resetColumnOrder()”Reset column order to the original configuration order.
resetColumnOrder(): void
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