Skip to content
Data TableAPI Reference

Core row queries & updates

comins-table@0.2.2React

0.2.0: Types and helpers on this page use the React-state contract from the root comins-table entry. Neutral /core has a separate type contract. See the migration guide for imports and cell policies.

Row update functions return the next state. Store that result rather than mutating input arrays or row objects. Changes to the values or order of the row ID array reset row, cell and range selection.

export declare function queryCominsRows<TData>(state: CominsTableState<TData>, predicate?: (row: TData, index: number) => boolean): TData[];

Returns a shallow array copy of rows, or filters it using original indexes when predicate is supplied. It does not apply sorting or pagination.

export declare function replaceCominsRows<TData>(state: CominsTableState<TData>, rows: readonly TData[]): CominsTableState<TData>;

Replaces rows, always clears selection even when IDs are unchanged, and shares the supplied array reference.

export declare function addCominsRows<TData>(state: CominsTableState<TData>, rows: readonly TData[]): CominsTableState<TData>;

Appends rows. It does not generate unique IDs or remove duplicate IDs.

export declare function updateCominsRows<TData>(state: CominsTableState<TData>, updates: ReadonlyArray<CominsRowUpdate<TData>>): CominsTableState<TData>;

Applies patches by ID. Object patches shallow-merge; function patches return a complete new row. The last update for an ID wins; unknown IDs are ignored. Selection is preserved when IDs and their order remain unchanged.

export declare function deleteCominsRows<TData>(state: CominsTableState<TData>, rowIds: readonly CominsRowId[]): CominsTableState<TData>;

Removes rows with the supplied IDs; unknown IDs are ignored.

export declare function moveCominsRow<TData>(state: CominsTableState<TData>, rowId: CominsRowId, targetIndex: number): CominsTableState<TData>;

Removes the row and inserts it at targetIndex in the remaining array, clamped to 0…remaining length. An unknown ID returns the original state. Sort rules remain active, so displayed sorted order can differ.

export declare function moveCominsRowToGroup<TData>(state: CominsTableState<TData>, options: CominsRowGroupMoveOptions<TData>): CominsTableState<TData>;

Changing membership requires setRowGroupId. With targetRowId, the target’s pre-removal index is clamped into the remaining array: a source before the target lands after it, and a source after the target lands before it. Without targetRowId, insertion is after the group’s last row, or at the array end for an empty group. Invalid IDs or a mismatched target group return the original state.

export type CominsRowUpdate<TData> = {
id: CominsRowId;
patch: Partial<TData> | ((row: TData) => TData);
};
Property Behavior / default
id ID of the row to update.
patch A shallow Partial patch or a function returning a new row; do not mutate the input row.
export type CominsRowGroupMoveOptions<TData> = {
getRowGroupId: (row: TData, dataIndex: number) => CominsRowId;
setRowGroupId?: (params: {
fromGroupId: CominsRowId;
row: TData;
rowId: CominsRowId;
toGroupId: CominsRowId;
}) => TData;
sourceRowId: CominsRowId;
targetGroupId: CominsRowId;
targetRowId?: CominsRowId;
};
Property Behavior / default
getRowGroupId Required group resolver using the row and current data index.
setRowGroupId Required for membership changes; returns a new row from fromGroupId/row/rowId/toGroupId.
sourceRowId Row ID to move.
targetGroupId Destination group ID.
targetRowId Optional positional target row ID; it must belong to targetGroupId.