UNPKG

@rtdui/datatable

Version:

React DataTable component based on Rtdui components

75 lines (74 loc) 2.92 kB
import { type OnChangeFn, type Table, type Row, type RowModel, type Updater, type RowData, type TableFeature } from "@tanstack/react-table"; export type RowActiveState = string | number | null; export interface RowActiveTableState { rowActive: RowActiveState; } export interface RowActiveOptions<TData extends RowData> { /** * - Enables/disables row active for all rows in the table OR * - A function that given a row, returns whether to enable/disable row active for that row * @default true */ enableRowActive?: boolean | ((row: Row<TData>) => boolean); /** * If provided, this function will be called with an `updaterFn` when `state.rowActive` changes. * This overrides the default internal state management, * so you will need to persist the state change either fully or partially outside of the table. */ onRowActiveChange?: OnChangeFn<RowActiveState>; } export interface RowActiveRow { /** * Returns whether or not the row can be actived. */ getCanActive: () => boolean; /** * Returns whether or not the row is actived. */ getIsActived: () => boolean; /** * Returns a handler that can be used to toggle the row. */ getToggleActivedHandler: () => (event: unknown) => void; /** * Active/deActive the row. */ toggleActived: (value?: boolean) => void; } export interface RowActiveInstance<TData extends RowData> { /** * Returns the row model of all rows that are actived after filtering has been applied. */ getFilteredActivedRowModel: () => RowModel<TData>; /** * Returns the row model of all rows that are actived after grouping has been applied. */ getGroupedActivedRowModel: () => RowModel<TData>; /** * Returns whether or not any rows on the current page are actived. */ getIsSomePageRowsActived: () => boolean; /** * Returns whether or not any rows in the table are actived. */ getIsSomeRowsActived: () => boolean; /** * Returns the core row model of all rows before row active has been applied. */ getPreActivedRowModel: () => RowModel<TData>; /** * Returns the row model of all rows that are actived. */ getActivedRowModel: () => RowModel<TData>; /** * Resets the **rowActive** state to the `initialState.rowActive`, or `true` can be passed to force a default blank state reset to `{}`. */ resetRowActive: (defaultState?: boolean) => void; /** * Sets or updates the `state.rowActive` state. */ setRowActive: (updater: Updater<RowActiveState>) => void; } export declare const RowActive: TableFeature; export declare function activeRowsFn<TData extends RowData>(table: Table<TData>, rowModel: RowModel<TData>): RowModel<TData>; export declare function isRowActived<TData extends RowData>(row: Row<TData>, active: RowActiveState): boolean;