Skip to content

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.

import { ReorderPlugin } from '@toolbox-web/grid/plugins/reorder-columns';
OptionTypeDefaultDescription
animationfalse | 'flip' | 'fade''flip'Animation type for column moves
animationDurationnumber200Animation duration in ms
KeyAction
Alt + ←Move focused column left
Alt + →Move focused column right
EventDetailCancelableDescription
column-move{ field, fromIndex, toIndex, columnOrder }YesFired when a column move is attempted
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 order
grid.on('column-move', ({ columnOrder }) => {
localStorage.setItem('columnOrder', JSON.stringify(columnOrder));
});
grid.on('column-move', (detail, e) => {
if (!isValidMoveWithinGroup(detail.field, detail.fromIndex, detail.toIndex)) {
e.preventDefault(); // Column snaps back to original position
}
});

Extends BaseGridPlugin

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

Get animation duration, allowing plugin config override. Uses base class animationDuration for default.

readonly animationDuration: number

Get the current column order from the grid.

getColumnOrder(): string[]

string[] - Array of field names in display order


Move a column to a new position.

moveColumn(field: string, toIndex: number): void
NameTypeDescription
fieldstringThe field name of the column to move
toIndexnumberThe target index

Set a specific column order.

setColumnOrder(order: string[]): void
NameTypeDescription
orderstring[]Array of field names in desired order

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