UNPKG

@tanstack/react-table

Version:

Headless UI for building powerful tables & datagrids for React.

231 lines 11.3 kB
import { ReactTable } from "./useTable.js"; import { AggregationFns, Cell, Column, ColumnDef, ColumnHelper, FilterFns, Header, HeaderGroup, Row, RowData, RowModel, SortFns, StockFeatures, Table, TableOptions, TableState } from "@tanstack/table-core"; //#region src/useLegacyTable.d.ts /** * @deprecated Use `createFilteredRowModel()` in the `filteredRowModel` feature slot with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the filtered row model. */ declare function getFilteredRowModel<TData extends RowData>(): RowModelFactory<TData>; /** * @deprecated Use `createSortedRowModel()` in the `sortedRowModel` feature slot with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the sorted row model. */ declare function getSortedRowModel<TData extends RowData>(): RowModelFactory<TData>; /** * @deprecated Use `createPaginatedRowModel()` with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the paginated row model. */ declare function getPaginationRowModel<TData extends RowData>(): RowModelFactory<TData>; /** * @deprecated Use `createExpandedRowModel()` with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the expanded row model. */ declare function getExpandedRowModel<TData extends RowData>(): RowModelFactory<TData>; /** * @deprecated Use `createGroupedRowModel()` in the `groupedRowModel` feature slot with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the grouped row model. */ declare function getGroupedRowModel<TData extends RowData>(): RowModelFactory<TData>; /** * @deprecated Use `createFacetedRowModel()` with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the faceted row model. */ declare function getFacetedRowModel<TData extends RowData>(): FacetedRowModelFactory<TData>; /** * @deprecated Use `createFacetedMinMaxValues()` with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the faceted min/max values. */ declare function getFacetedMinMaxValues<TData extends RowData>(): FacetedMinMaxValuesFactory<TData>; /** * @deprecated Use `createFacetedUniqueValues()` with the new `useTable` hook instead. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It acts as a marker to enable the faceted unique values. */ declare function getFacetedUniqueValues<TData extends RowData>(): FacetedUniqueValuesFactory<TData>; /** * @deprecated The core row model is always created automatically in v9. * * This is a stub function for v8 API compatibility with `useLegacyTable`. * It does nothing - the core row model is always available. */ declare function getCoreRowModel<TData extends RowData>(): RowModelFactory<TData>; /** * Row model factory function type from v8 API */ type RowModelFactory<TData extends RowData> = (table: Table<StockFeatures, TData>) => () => RowModel<StockFeatures, TData>; /** * Faceted row model factory function type from v8 API */ type FacetedRowModelFactory<TData extends RowData> = (table: Table<StockFeatures, TData>, columnId: string) => () => RowModel<StockFeatures, TData>; /** * Faceted min/max values factory function type from v8 API */ type FacetedMinMaxValuesFactory<TData extends RowData> = (table: Table<StockFeatures, TData>, columnId: string) => () => undefined | [number, number]; /** * Faceted unique values factory function type from v8 API */ type FacetedUniqueValuesFactory<TData extends RowData> = (table: Table<StockFeatures, TData>, columnId: string) => () => Map<any, number>; /** * Legacy v8-style row model options */ interface LegacyRowModelOptions<TData extends RowData> { /** * Returns the core row model for the table. * @deprecated This option is no longer needed in v9. The core row model is always created automatically. */ getCoreRowModel?: RowModelFactory<TData>; /** * Returns the filtered row model for the table. * @deprecated Use the `filteredRowModel`/`filterFns` slots on the `features` option with `createFilteredRowModel()` instead. */ getFilteredRowModel?: RowModelFactory<TData>; /** * Returns the sorted row model for the table. * @deprecated Use the `sortedRowModel`/`sortFns` slots on the `features` option with `createSortedRowModel()` instead. */ getSortedRowModel?: RowModelFactory<TData>; /** * Returns the paginated row model for the table. * @deprecated Use the `paginatedRowModel` slot on the `features` option with `createPaginatedRowModel()` instead. */ getPaginationRowModel?: RowModelFactory<TData>; /** * Returns the expanded row model for the table. * @deprecated Use the `expandedRowModel` slot on the `features` option with `createExpandedRowModel()` instead. */ getExpandedRowModel?: RowModelFactory<TData>; /** * Returns the grouped row model for the table. * @deprecated Use `columnGroupingFeature` with the `groupedRowModel` slot and `createGroupedRowModel()` instead. Add `rowAggregationFeature` separately when grouped rows aggregate values. */ getGroupedRowModel?: RowModelFactory<TData>; /** * Returns the faceted row model for a column. * @deprecated Use the `facetedRowModel` slot on the `features` option with `createFacetedRowModel()` instead. */ getFacetedRowModel?: FacetedRowModelFactory<TData>; /** * Returns the faceted min/max values for a column. * @deprecated Use the `facetedMinMaxValues` slot on the `features` option with `createFacetedMinMaxValues()` instead. */ getFacetedMinMaxValues?: FacetedMinMaxValuesFactory<TData>; /** * Returns the faceted unique values for a column. * @deprecated Use the `facetedUniqueValues` slot on the `features` option with `createFacetedUniqueValues()` instead. */ getFacetedUniqueValues?: FacetedUniqueValuesFactory<TData>; /** * Additional filter functions to apply to the table. * @deprecated Use the `filteredRowModel`/`filterFns` slots on the `features` option with `createFilteredRowModel()` instead. */ filterFns?: FilterFns; /** * Additional sort functions to apply to the table. * @deprecated Use the `sortedRowModel`/`sortFns` slots on the `features` option with `createSortedRowModel()` instead. */ sortFns?: SortFns; /** * Additional aggregation functions to apply to the table. * @deprecated Use `rowAggregationFeature` with the `aggregationFns` slot instead. Add `columnGroupingFeature` and `groupedRowModel` only when grouping rows. */ aggregationFns?: AggregationFns; } /** * Legacy v8-style table options that work with useLegacyTable. * * This type omits `features` and instead accepts the v8-style * `get*RowModel` function options. * * @deprecated This is a compatibility layer for migrating from v8. Use `useTable` with an explicit `features` option instead. */ type LegacyTableOptions<TData extends RowData> = Omit<TableOptions<StockFeatures, TData>, 'features'> & LegacyRowModelOptions<TData>; /** * Legacy table instance type that includes the v8-style `getState()` method. * * @deprecated Use `useTable` with explicit state selection instead. */ type LegacyReactTable<TData extends RowData> = ReactTable<StockFeatures, TData, TableState<StockFeatures>> & { /** * Returns the current table state. * @deprecated In v9, access state directly via `table.state` or use `table.state` for the full state. */ getState: () => TableState<StockFeatures>; /** * Sets the current table state. * @deprecated In v9, access state directly via `table.baseAtoms` */ setState: (state: TableState<StockFeatures>) => void; }; /** @deprecated Use Column<TFeatures, TData, TValue> with useTable instead. */ type LegacyColumn<TData extends RowData, TValue = unknown> = Column<StockFeatures, TData, TValue>; /** @deprecated Use Row<TFeatures, TData> with useTable instead. */ type LegacyRow<TData extends RowData> = Row<StockFeatures, TData>; /** @deprecated Use Cell<TFeatures, TData, TValue> with useTable instead. */ type LegacyCell<TData extends RowData, TValue = unknown> = Cell<StockFeatures, TData, TValue>; /** @deprecated Use Header<TFeatures, TData, TValue> with useTable instead. */ type LegacyHeader<TData extends RowData, TValue = unknown> = Header<StockFeatures, TData, TValue>; /** @deprecated Use HeaderGroup<TFeatures, TData> with useTable instead. */ type LegacyHeaderGroup<TData extends RowData> = HeaderGroup<StockFeatures, TData>; /** @deprecated Use ColumnDef<TFeatures, TData, TValue> with useTable instead. */ type LegacyColumnDef<TData extends RowData, TValue = unknown> = ColumnDef<StockFeatures, TData, TValue>; /** @deprecated Use Table<TFeatures, TData> with useTable instead. */ type LegacyTable<TData extends RowData> = Table<StockFeatures, TData>; /** * @deprecated Use `createColumnHelper<TFeatures, TData>()` with useTable instead. * * A column helper with StockFeatures pre-bound for use with useLegacyTable. * Only requires TData—no need to specify TFeatures. */ declare function legacyCreateColumnHelper<TData extends RowData>(): ColumnHelper<StockFeatures, TData>; /** * @deprecated This hook is provided as a compatibility layer for migrating from TanStack Table v8. * * Use the new `useTable` hook instead with an explicit `features` option: * * ```tsx * // New v9 API * const features = tableFeatures({ * columnFilteringFeature, * rowSortingFeature, * rowPaginationFeature, * filteredRowModel: createFilteredRowModel(), * sortedRowModel: createSortedRowModel(), * paginatedRowModel: createPaginatedRowModel(), * filterFns, * sortFns, * }) * * const table = useTable({ * features, * columns, * data, * }) * ``` * * Key differences from v8: * - Features are tree-shakeable - only import what you use * - Row models and fn registries are explicitly passed on the `features` option * - Use `table.Subscribe` for fine-grained re-renders * - State is accessed via `table.state` after selecting with the 2nd argument * * @param options - Legacy v8-style table options * @returns A table instance with the full state subscribed and a `getState()` method */ declare function useLegacyTable<TData extends RowData>(options: LegacyTableOptions<TData>): LegacyReactTable<TData>; //#endregion export { FacetedMinMaxValuesFactory, FacetedRowModelFactory, FacetedUniqueValuesFactory, LegacyCell, LegacyColumn, LegacyColumnDef, LegacyHeader, LegacyHeaderGroup, LegacyReactTable, LegacyRow, LegacyRowModelOptions, LegacyTable, LegacyTableOptions, RowModelFactory, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, legacyCreateColumnHelper, useLegacyTable };