Skip to content
Data TableAPI Reference

Viewport hook

comins-table@0.2.2React

Load blocks around the current scroll position without allocating the full dataset. useCominsViewport owns consumer React state; the Table requests the required ranges.

export declare function useCominsViewport<T>(options: CominsViewportOptions<T>): {
data: CominsViewportData<T>;
tableProps: {
data: CominsViewportData<T>;
onChangeData: (next: CominsViewportData<T>) => void;
onViewportRequest: (request: CominsViewportRequest) => Promise<void>;
viewportDatasource: CominsViewportDatasource;
virtualized: true;
};
};

data is the current snapshot. Spread tableProps into CominsTable and supply columns and a stable getRowId. tableProps contains data, onChangeData, onViewportRequest, viewportDatasource and virtualized: true. Overriding these callbacks requires managing the controlled state yourself.

Changing queryKey, rowCount, blockSize or cacheSize creates a new hook snapshot. Change queryKey when the query order or filters change. Replacing the getRows function alone does not reset the dataset. Aborted requests and responses from an earlier initial state are ignored; fetch exceptions become error request states.

export type CominsViewportOptions<T> = {
rowCount: number;
queryKey: CominsViewportRevision;
getRows: (request: CominsViewportRequest) => readonly T[] | Promise<readonly T[]>;
blockSize?: number;
cacheSize?: number;
maxConcurrentRequests?: number;
heightCacheSize?: number;
onEdit?: (changes: readonly CominsViewportPatch<T>[]) => void;
};
Property Behavior / default
rowCount Required non-negative safe integer for the total row count. Resolve the count before enabling this mode.
queryKey Required string/number dataset revision. Change it when search, sorting or index order changes.
getRows Required range loader receiving [startIndex, endIndex) and signal. Return exactly endIndex − startIndex non-null, defined rows, including the final block.
blockSize Defaults to 100 rows. Invalid positive-safe-integer input falls back to the default.
cacheSize Defaults to 12 blocks. Protected visible and active-request blocks can exceed this target.
maxConcurrentRequests Defaults to 2 concurrent Table range requests. Invalid positive-safe-integer input falls back to 2.
heightCacheSize Defaults to 64 blocks for measured row heights, separate from the data cache.
onEdit Optional notification with absolute-index/new-row patches, called synchronously before the local snapshot update. The app persists edits and merges unsaved values into later loads after eviction.

Supports fixed/automatic row height, column pinning/resizing and editing loaded rows. Do not combine with Tree, Row Grouping, Row Detail, row moves, append loading or pagination. Apply sorting/filtering through external query conditions. Server push and automatic loading for unloaded-row edits are not provided.