hightable
Version:
A dynamic windowed scrolling table component for react
77 lines (76 loc) • 2.18 kB
TypeScript
import { AsyncRow, Cells } from './row.js';
import { OrderBy } from './sort.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 DataFrame {
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 DataFrame.
*
* 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 DataFrame to add getColumn method to
* @returns getColumn function
*/
export declare function getGetColumn(data: DataFrame): GetColumn;
export declare function getRanks({ data, column }: {
data: DataFrame;
column: string;
}): Promise<number[]>;
export declare function computeDataIndexes(orderBy: {
direction: 'ascending' | 'descending';
ranks: number[];
}[]): number[];
export declare function getUnsortedRanks({ data }: {
data: DataFrame;
}): Promise<number[]>;
/**
* Wraps a DataFrame to make it sortable.
*
* If the DataFrame is already sortable, it will return the original DataFrame.
*
* 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 DataFrame to make sortable
* @returns DataFrame with sortable rows
*/
export declare function sortableDataFrame(data: DataFrame): DataFrame;
export declare function arrayDataFrame(data: Cells[]): DataFrame;