UNPKG

hightable

Version:

A dynamic windowed scrolling table component for react

78 lines (77 loc) 2.25 kB
import { OrderBy } from '../../sort.js'; import type { Cells } from '../index.js'; import { AsyncRow } from './row.js'; /** * Function that gets values in a column. * * If start and end are provided, only get values in that range. * Negative start and end are allowed. * * @param column Column name * @param start Start index (inclusive) * @param end End index (exclusive) * * @returns Values in the column */ export type GetColumn = ({ column, start, end }: { column: string; start?: number; end?: number; }) => Promise<any[]>; /** * Streamable row data */ export interface DataFrameV1 { header: string[]; numRows: number; rows({ start, end, orderBy }: { start: number; end: number; orderBy?: OrderBy; }): AsyncRow[]; getColumn?: GetColumn; sortable?: boolean; } /** * Return getColumn() function to apply on a DataFrameV1. * * Uses df.getColumn() if provided. Otherwise, it creates a naive implementation that * fetches full rows (AsyncRow) then extracts the column values. * * It will benefit of cached rows: * ``` * const getColumn = getGetColumn(rowCache(data)) * ``` * * @param data DataFrameV1 to add getColumn method to * @returns getColumn function */ export declare function getGetColumn(data: DataFrameV1): GetColumn; export declare function getRanks({ data, column }: { data: DataFrameV1; column: string; }): Promise<number[]>; export declare function computeDataIndexes(orderBy: { direction: 'ascending' | 'descending'; ranks: number[]; }[]): number[]; export declare function getUnsortedRanks({ data }: { data: DataFrameV1; }): Promise<number[]>; /** * Wraps a DataFrameV1 to make it sortable. * * If the DataFrameV1 is already sortable, it will return the original DataFrameV1. * * It takes advantage of cached rows to sort the data faster: * ``` * const df = sortableDataFrame(rowCache(data)) * ``` * * If .getColumn() exists, it's used to sort the rows by the provided column. * * @param data DataFrameV1 to make sortable * @returns DataFrameV1 with sortable rows */ export declare function sortableDataFrame(data: DataFrameV1): DataFrameV1; export declare function arrayDataFrame(data: Cells[]): DataFrameV1;