import { type BuiltInAggregationFn } from "../aggregation-fns.js"; import type { CellContext } from "../core/cell.js"; import type { TableFeature } from "../core/table.js"; import type { AggregationFns, Column, ColumnDefTemplate, ColumnMeta, OnChangeFn, Row, RowData, RowModel, TableInstance, Updater } from "../types.js"; export type GroupingState = string[]; export interface GroupingTableState { grouping: GroupingState; } export type AggregationFn = ( /** * The id of the column. */ columnId: string, /** @inheritDoc */ leafRows: Row[], /** @inheritDoc */ childRows: Row[]) => any; export type CustomAggregationFns = Record>; export type AggregationFnOption = "auto" | keyof AggregationFns | BuiltInAggregationFn | AggregationFn; export interface GroupingColumnDef { /** * The cell to display each row for the column if the cell is an aggregate. */ aggregatedCell?: ColumnDefTemplate>; /** * The resolved aggregation function for the column. * * @inheritDoc */ aggregationFn?: AggregationFnOption; /** * Enables/disables grouping for this column. */ enableGrouping?: boolean; /** * Specify a value to be used for grouping rows on this column. If this option is * not specified, the value derived from `accessorKey` / `accessorFn` will be used * instead. */ getGroupingValue?: (row: TData) => any; } export interface GroupingColumn { /** * Returns the aggregation function for the column. * * @inheritDoc */ getAggregationFn: () => AggregationFn | undefined; /** * Returns the automatically inferred aggregation function for the column. * * @inheritDoc */ getAutoAggregationFn: () => AggregationFn | undefined; /** * Returns whether the column can be grouped. */ getCanGroup: () => boolean; /** * Returns the index of the column in the grouping state. */ getGroupedIndex: () => number; /** * Returns whether the column is currently grouped. */ getIsGrouped: () => boolean; /** * Returns a function that toggles the grouping state of the column. This is * useful for passing to the `onClick` prop of a button. */ getToggleGroupingHandler: () => () => void; /** * Toggles the grouping state of the column. */ toggleGrouping: () => void; } export interface GroupingRow { /** @internal */ _groupingValuesCache: Record; /** * Returns the grouping value for any row and column (including leaf rows). */ getGroupingValue: (columnId: string) => unknown; /** * Returns whether the row is currently grouped. */ getIsGrouped: () => boolean; /** * If this row is grouped, this is the id of the column that this row is grouped * by. */ groupingColumnId?: string; /** * If this row is grouped, this is the unique/shared value for the * `groupingColumnId` for all of the rows in this group. */ groupingValue?: unknown; } export interface GroupingCell { /** * Returns whether the cell is currently aggregated. */ getIsAggregated: () => boolean; /** * Returns whether the cell is currently grouped. */ getIsGrouped: () => boolean; /** * Returns whether the cell is currently a placeholder cell. */ getIsPlaceholder: () => boolean; } export interface ColumnDefaultOptions { enableGrouping: boolean; onGroupingChange: OnChangeFn; } interface GroupingOptionsBase { /** * Enables/disables grouping for the table. */ enableGrouping?: boolean; /** * Returns the row model after grouping has taken place, but no further. */ getGroupedRowModel?: ( /** @inheritDoc */ table: TableInstance) => () => RowModel; /** * Grouping columns are automatically reordered by default to the start of the * columns list. If you would rather remove them or leave them as-is, set the * appropriate mode here. */ groupedColumnMode?: false | "reorder" | "remove"; /** * Enables manual grouping. If this option is set to `true`, the table will not * automatically group rows using `getGroupedRowModel()` and instead will expect * you to manually group the rows before passing them to the table. This is useful * if you are doing server-side grouping and aggregation. */ manualGrouping?: boolean; /** * If this function is provided, it will be called when the grouping state changes * and you will be expected to manage the state yourself. You can pass the managed * state back to the table via the `tableOptions.state.grouping` option. */ onGroupingChange?: OnChangeFn; } type ResolvedAggregationFns = keyof AggregationFns extends never ? { /** @inheritDoc */ aggregationFns?: Record>; } : { /** @inheritDoc */ aggregationFns: Record>; }; export interface GroupingOptions extends GroupingOptionsBase, ResolvedAggregationFns { } export type GroupingColumnMode = false | "reorder" | "remove"; export interface GroupingInstance { /** @internal */ _getGroupedRowModel?: () => RowModel; /** * Returns the row model for the table after grouping has been applied. */ getGroupedRowModel: () => RowModel; /** * Returns the row model for the table before any grouping has been applied. */ getPreGroupedRowModel: () => RowModel; /** * Resets the `grouping` state to `initialState.grouping`, or `true` can be * passed to force a default blank state reset to `[]`. */ resetGrouping: (defaultState?: boolean) => void; /** * Updates the grouping state of the table via an update function or value. */ setGrouping: (updater: Updater) => void; } export declare const Grouping: TableFeature; export declare function orderColumns(leafColumns: Column[], grouping: string[], groupedColumnMode?: GroupingColumnMode): Column[]; export {}; //# sourceMappingURL=grouping.d.ts.map