Skip to content
Data TableAPI Reference

Tree drag options and destinations

comins-table@0.2.2React

treeRowDrag reorders siblings or changes parents within one tree. Enable it with {} and connect onChangeData. Omission disables dragging; manual moves are disabled while sorting.

Moves the whole subtree, preserving collapsed descendants and expand values. Dropping inside a collapsed parent does not expand it. Restrict sources through rowProps.disabled/draggable. canDrop can narrow permission but cannot permit cycles or invalid destinations.

Start with pointer input or Space, choose a destination with arrow keys, confirm with Enter, or cancel with Escape. Left/right keys also apply when reparenting is enabled. A false onBeforeRowDrag veto produces no after notification. A started gesture reports its result through onAfterDragRow. See event payloads and Tree setup code.

allowReparent?: boolean;

Default false. Allows only sibling moves under the same parent; true also permits moving between parents/root.

canDrop?: (context: CominsTreeDropContext<TItem>) => boolean;

Omission allows structurally valid moves. Return false to restrict them. May run during preview and commit; keep it synchronous and free of side effects.

parentId: CominsRowId | null;

Required destination parent ID; null denotes the root array.

beforeRowId: CominsRowId | null;

Required sibling ID to insert before; null appends to the sibling array.

source: CominsVisibleTreeRow<TItem>;

Visible source-node information.

target: CominsVisibleTreeRow<TItem>;

Target node selected by pointer/keyboard input.

destination: CominsTreeMoveDestination;

Resolved location as parentId and beforeRowId.

position: CominsTreeDropPosition;

before/after/inside relative to the target.

depth: number;

Zero-based depth; roots are 0.

expanded: boolean;

Current expansion state.

hasChildren: boolean;

Whether the node has children.

item: TItem;

Source business data; treat as read-only.

path: readonly number[];

Array-index path to the node, which can change after moving.

rowId: CominsRowId;

Stable ID unique across all depths.

export declare function moveCominsTreeNode<TItem>(nodes: readonly CominsTreeNode<TItem>[], rowId: CominsRowId, destination: CominsTreeMoveDestination, getRowId: (item: TItem, index: number) => CominsRowId, options?: {
allowReparent?: boolean;
}): readonly CominsTreeNode<TItem>[];

Import from comins-table. nodes, rowId, destination, and getRowId are required; options.allowReparent defaults to false. Returns a new array, or the original reference for unchanged/invalid moves. Duplicate IDs throw. It emits no UI events and does not update state; apply the result to parent state.