@tanstack/table-core 8.19.2 → 9.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/aggregationFns.cjs +94 -0
- package/dist/cjs/aggregationFns.cjs.map +1 -0
- package/dist/cjs/aggregationFns.d.cts +14 -0
- package/dist/cjs/columnHelper.cjs +19 -0
- package/dist/cjs/columnHelper.cjs.map +1 -0
- package/dist/cjs/columnHelper.d.cts +9 -0
- package/dist/cjs/core/cell.cjs +38 -0
- package/dist/cjs/core/cell.cjs.map +1 -0
- package/dist/cjs/core/cell.d.cts +50 -0
- package/dist/cjs/core/column.cjs +81 -0
- package/dist/cjs/core/column.cjs.map +1 -0
- package/dist/cjs/core/column.d.cts +56 -0
- package/dist/cjs/core/headers.cjs +310 -0
- package/dist/cjs/core/headers.cjs.map +1 -0
- package/dist/cjs/core/headers.d.cts +195 -0
- package/dist/cjs/core/row.cjs +92 -0
- package/dist/cjs/core/row.cjs.map +1 -0
- package/dist/cjs/core/row.d.cts +92 -0
- package/dist/cjs/core/table.cjs +232 -0
- package/dist/cjs/core/table.cjs.map +1 -0
- package/dist/cjs/core/table.d.cts +229 -0
- package/dist/cjs/features/ColumnFaceting.cjs +29 -0
- package/dist/cjs/features/ColumnFaceting.cjs.map +1 -0
- package/dist/cjs/features/ColumnFaceting.d.cts +35 -0
- package/dist/cjs/features/ColumnFiltering.cjs +137 -0
- package/dist/cjs/features/ColumnFiltering.cjs.map +1 -0
- package/dist/cjs/features/ColumnFiltering.d.cts +195 -0
- package/dist/cjs/features/ColumnGrouping.cjs +133 -0
- package/dist/cjs/features/ColumnGrouping.cjs.map +1 -0
- package/dist/cjs/features/ColumnGrouping.d.cts +202 -0
- package/dist/cjs/features/ColumnOrdering.cjs +76 -0
- package/dist/cjs/features/ColumnOrdering.cjs.map +1 -0
- package/dist/cjs/features/ColumnOrdering.d.cts +54 -0
- package/dist/cjs/features/ColumnPinning.cjs +145 -0
- package/dist/cjs/features/ColumnPinning.cjs.map +1 -0
- package/dist/cjs/features/ColumnPinning.d.cts +127 -0
- package/dist/cjs/features/ColumnSizing.cjs +307 -0
- package/dist/cjs/features/ColumnSizing.cjs.map +1 -0
- package/dist/cjs/features/ColumnSizing.d.cts +194 -0
- package/dist/cjs/features/ColumnVisibility.cjs +144 -0
- package/dist/cjs/features/ColumnVisibility.cjs.map +1 -0
- package/dist/cjs/features/ColumnVisibility.d.cts +130 -0
- package/dist/cjs/features/GlobalFaceting.cjs +29 -0
- package/dist/cjs/features/GlobalFaceting.cjs.map +1 -0
- package/dist/cjs/features/GlobalFaceting.d.cts +27 -0
- package/dist/cjs/features/GlobalFiltering.cjs +50 -0
- package/dist/cjs/features/GlobalFiltering.cjs.map +1 -0
- package/dist/cjs/features/GlobalFiltering.d.cts +80 -0
- package/dist/cjs/features/RowExpanding.cjs +152 -0
- package/dist/cjs/features/RowExpanding.cjs.map +1 -0
- package/dist/cjs/features/RowExpanding.d.cts +155 -0
- package/dist/cjs/features/RowPagination.cjs +161 -0
- package/dist/cjs/features/RowPagination.cjs.map +1 -0
- package/dist/cjs/features/RowPagination.d.cts +166 -0
- package/dist/cjs/features/RowPinning.cjs +132 -0
- package/dist/cjs/features/RowPinning.cjs.map +1 -0
- package/dist/cjs/features/RowPinning.d.cts +99 -0
- package/dist/cjs/features/RowSelection.cjs +296 -0
- package/dist/cjs/features/RowSelection.cjs.map +1 -0
- package/dist/cjs/features/RowSelection.d.cts +177 -0
- package/dist/cjs/features/RowSorting.cjs +200 -0
- package/dist/cjs/features/RowSorting.cjs.map +1 -0
- package/dist/cjs/features/RowSorting.d.cts +238 -0
- package/dist/cjs/filterFns.cjs +88 -0
- package/dist/cjs/filterFns.cjs.map +1 -0
- package/dist/cjs/filterFns.d.cts +14 -0
- package/{build/lib/index.js → dist/cjs/index.cjs} +41 -53
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +34 -0
- package/{build/lib/sortingFns.js → dist/cjs/sortingFns.cjs} +23 -52
- package/dist/cjs/sortingFns.cjs.map +1 -0
- package/dist/cjs/sortingFns.d.cts +12 -0
- package/dist/cjs/types.d.cts +120 -0
- package/{build/lib/utils/filterRowsUtils.js → dist/cjs/utils/filterRowsUtils.cjs} +34 -46
- package/dist/cjs/utils/filterRowsUtils.cjs.map +1 -0
- package/dist/cjs/utils/filterRowsUtils.d.cts +3 -0
- package/dist/cjs/utils/getCoreRowModel.cjs +54 -0
- package/dist/cjs/utils/getCoreRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getCoreRowModel.d.cts +3 -0
- package/dist/cjs/utils/getExpandedRowModel.cjs +41 -0
- package/dist/cjs/utils/getExpandedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getExpandedRowModel.d.cts +8 -0
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs +35 -0
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs.map +1 -0
- package/dist/cjs/utils/getFacetedMinMaxValues.d.cts +3 -0
- package/dist/cjs/utils/getFacetedRowModel.cjs +35 -0
- package/dist/cjs/utils/getFacetedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getFacetedRowModel.d.cts +3 -0
- package/dist/cjs/utils/getFacetedUniqueValues.cjs +37 -0
- package/dist/cjs/utils/getFacetedUniqueValues.cjs.map +1 -0
- package/dist/cjs/utils/getFacetedUniqueValues.d.cts +3 -0
- package/dist/cjs/utils/getFilteredRowModel.cjs +116 -0
- package/dist/cjs/utils/getFilteredRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getFilteredRowModel.d.cts +3 -0
- package/dist/cjs/utils/getGroupedRowModel.cjs +118 -0
- package/dist/cjs/utils/getGroupedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getGroupedRowModel.d.cts +3 -0
- package/dist/cjs/utils/getPaginationRowModel.cjs +49 -0
- package/dist/cjs/utils/getPaginationRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getPaginationRowModel.d.cts +5 -0
- package/dist/cjs/utils/getSortedRowModel.cjs +88 -0
- package/dist/cjs/utils/getSortedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getSortedRowModel.d.cts +3 -0
- package/{build/lib/utils.js → dist/cjs/utils.cjs} +26 -39
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +39 -0
- package/{build/lib → dist/esm}/aggregationFns.d.ts +2 -1
- package/dist/esm/aggregationFns.js +94 -0
- package/dist/esm/aggregationFns.js.map +1 -0
- package/{build/lib → dist/esm}/columnHelper.d.ts +3 -2
- package/dist/esm/columnHelper.js +19 -0
- package/{build/lib → dist/esm}/columnHelper.js.map +1 -1
- package/{build/lib → dist/esm}/core/cell.d.ts +2 -1
- package/dist/esm/core/cell.js +38 -0
- package/dist/esm/core/cell.js.map +1 -0
- package/{build/lib → dist/esm}/core/column.d.ts +2 -1
- package/dist/esm/core/column.js +81 -0
- package/dist/esm/core/column.js.map +1 -0
- package/{build/lib → dist/esm}/core/headers.d.ts +1 -0
- package/dist/esm/core/headers.js +310 -0
- package/dist/esm/core/headers.js.map +1 -0
- package/{build/lib → dist/esm}/core/row.d.ts +2 -1
- package/dist/esm/core/row.js +92 -0
- package/dist/esm/core/row.js.map +1 -0
- package/{build/lib → dist/esm}/core/table.d.ts +10 -1
- package/dist/esm/core/table.js +232 -0
- package/dist/esm/core/table.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnFaceting.d.ts +1 -0
- package/{build/lib → dist/esm}/features/ColumnFaceting.js +6 -19
- package/{build/lib → dist/esm}/features/ColumnFaceting.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnFiltering.d.ts +1 -0
- package/dist/esm/features/ColumnFiltering.js +137 -0
- package/dist/esm/features/ColumnFiltering.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnGrouping.d.ts +1 -0
- package/dist/esm/features/ColumnGrouping.js +133 -0
- package/dist/esm/features/ColumnGrouping.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnOrdering.d.ts +1 -0
- package/dist/esm/features/ColumnOrdering.js +76 -0
- package/dist/esm/features/ColumnOrdering.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnPinning.d.ts +1 -0
- package/dist/esm/features/ColumnPinning.js +145 -0
- package/dist/esm/features/ColumnPinning.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnSizing.d.ts +2 -1
- package/dist/esm/features/ColumnSizing.js +307 -0
- package/dist/esm/features/ColumnSizing.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnVisibility.d.ts +1 -0
- package/dist/esm/features/ColumnVisibility.js +144 -0
- package/dist/esm/features/ColumnVisibility.js.map +1 -0
- package/{build/lib → dist/esm}/features/GlobalFaceting.d.ts +1 -0
- package/{build/lib → dist/esm}/features/GlobalFaceting.js +8 -21
- package/dist/esm/features/GlobalFaceting.js.map +1 -0
- package/{build/lib → dist/esm}/features/GlobalFiltering.d.ts +1 -0
- package/dist/esm/features/GlobalFiltering.js +50 -0
- package/dist/esm/features/GlobalFiltering.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowExpanding.d.ts +1 -0
- package/{build/lib → dist/esm}/features/RowExpanding.js +37 -58
- package/dist/esm/features/RowExpanding.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowPagination.d.ts +1 -0
- package/dist/esm/features/RowPagination.js +161 -0
- package/dist/esm/features/RowPagination.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowPinning.d.ts +1 -0
- package/dist/esm/features/RowPinning.js +132 -0
- package/dist/esm/features/RowPinning.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowSelection.d.ts +1 -0
- package/dist/esm/features/RowSelection.js +296 -0
- package/dist/esm/features/RowSelection.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowSorting.d.ts +1 -0
- package/dist/esm/features/RowSorting.js +200 -0
- package/dist/esm/features/RowSorting.js.map +1 -0
- package/{build/lib → dist/esm}/filterFns.d.ts +2 -1
- package/dist/esm/filterFns.js +88 -0
- package/dist/esm/filterFns.js.map +1 -0
- package/dist/esm/index.d.ts +34 -0
- package/dist/esm/index.js +88 -0
- package/dist/esm/index.js.map +1 -0
- package/{build/lib → dist/esm}/sortingFns.d.ts +2 -1
- package/dist/esm/sortingFns.js +91 -0
- package/dist/esm/sortingFns.js.map +1 -0
- package/{build/lib → dist/esm}/types.d.ts +29 -28
- package/{build/lib → dist/esm}/utils/filterRowsUtils.d.ts +1 -0
- package/dist/esm/utils/filterRowsUtils.js +99 -0
- package/dist/esm/utils/filterRowsUtils.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getCoreRowModel.d.ts +1 -0
- package/dist/esm/utils/getCoreRowModel.js +54 -0
- package/dist/esm/utils/getCoreRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getExpandedRowModel.d.ts +1 -0
- package/dist/esm/utils/getExpandedRowModel.js +41 -0
- package/dist/esm/utils/getExpandedRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getFacetedMinMaxValues.d.ts +1 -0
- package/dist/esm/utils/getFacetedMinMaxValues.js +35 -0
- package/dist/esm/utils/getFacetedMinMaxValues.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getFacetedRowModel.d.ts +1 -0
- package/dist/esm/utils/getFacetedRowModel.js +35 -0
- package/{build/lib → dist/esm}/utils/getFacetedRowModel.js.map +1 -1
- package/{build/lib → dist/esm}/utils/getFacetedUniqueValues.d.ts +1 -0
- package/dist/esm/utils/getFacetedUniqueValues.js +37 -0
- package/dist/esm/utils/getFacetedUniqueValues.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getFilteredRowModel.d.ts +1 -0
- package/dist/esm/utils/getFilteredRowModel.js +116 -0
- package/{build/lib → dist/esm}/utils/getFilteredRowModel.js.map +1 -1
- package/{build/lib → dist/esm}/utils/getGroupedRowModel.d.ts +1 -0
- package/dist/esm/utils/getGroupedRowModel.js +118 -0
- package/dist/esm/utils/getGroupedRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getPaginationRowModel.d.ts +1 -0
- package/dist/esm/utils/getPaginationRowModel.js +49 -0
- package/dist/esm/utils/getPaginationRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getSortedRowModel.d.ts +1 -0
- package/dist/esm/utils/getSortedRowModel.js +88 -0
- package/{build/lib → dist/esm}/utils/getSortedRowModel.js.map +1 -1
- package/{build/lib → dist/esm}/utils.d.ts +2 -1
- package/dist/esm/utils.js +98 -0
- package/{build/lib → dist/esm}/utils.js.map +1 -1
- package/package.json +14 -10
- package/src/core/cell.ts +2 -2
- package/src/core/column.ts +2 -2
- package/src/core/headers.ts +5 -5
- package/src/core/row.ts +4 -4
- package/src/core/table.ts +43 -7
- package/src/features/ColumnFaceting.ts +1 -1
- package/src/features/ColumnFiltering.ts +6 -6
- package/src/features/ColumnGrouping.ts +7 -7
- package/src/features/ColumnOrdering.ts +4 -4
- package/src/features/ColumnPinning.ts +5 -5
- package/src/features/ColumnSizing.ts +6 -6
- package/src/features/ColumnVisibility.ts +5 -5
- package/src/features/GlobalFaceting.ts +1 -1
- package/src/features/GlobalFiltering.ts +4 -4
- package/src/features/RowExpanding.ts +4 -4
- package/src/features/RowPagination.ts +3 -3
- package/src/features/RowPinning.ts +4 -4
- package/src/features/RowSelection.ts +4 -4
- package/src/features/RowSorting.ts +5 -5
- package/src/types.ts +8 -8
- package/src/utils/filterRowsUtils.ts +3 -3
- package/src/utils/getCoreRowModel.ts +2 -2
- package/src/utils/getGroupedRowModel.ts +2 -2
- package/build/lib/aggregationFns.js +0 -108
- package/build/lib/aggregationFns.js.map +0 -1
- package/build/lib/columnHelper.js +0 -71
- package/build/lib/core/cell.js +0 -42
- package/build/lib/core/cell.js.map +0 -1
- package/build/lib/core/column.js +0 -80
- package/build/lib/core/column.js.map +0 -1
- package/build/lib/core/headers.js +0 -270
- package/build/lib/core/headers.js.map +0 -1
- package/build/lib/core/row.js +0 -89
- package/build/lib/core/row.js.map +0 -1
- package/build/lib/core/table.js +0 -212
- package/build/lib/core/table.js.map +0 -1
- package/build/lib/features/ColumnFiltering.js +0 -151
- package/build/lib/features/ColumnFiltering.js.map +0 -1
- package/build/lib/features/ColumnGrouping.js +0 -142
- package/build/lib/features/ColumnGrouping.js.map +0 -1
- package/build/lib/features/ColumnOrdering.js +0 -84
- package/build/lib/features/ColumnOrdering.js.map +0 -1
- package/build/lib/features/ColumnPinning.js +0 -130
- package/build/lib/features/ColumnPinning.js.map +0 -1
- package/build/lib/features/ColumnSizing.js +0 -270
- package/build/lib/features/ColumnSizing.js.map +0 -1
- package/build/lib/features/ColumnVisibility.js +0 -99
- package/build/lib/features/ColumnVisibility.js.map +0 -1
- package/build/lib/features/GlobalFaceting.js.map +0 -1
- package/build/lib/features/GlobalFiltering.js +0 -63
- package/build/lib/features/GlobalFiltering.js.map +0 -1
- package/build/lib/features/RowExpanding.js.map +0 -1
- package/build/lib/features/RowPagination.js +0 -169
- package/build/lib/features/RowPagination.js.map +0 -1
- package/build/lib/features/RowPinning.js +0 -145
- package/build/lib/features/RowPinning.js.map +0 -1
- package/build/lib/features/RowSelection.js +0 -391
- package/build/lib/features/RowSelection.js.map +0 -1
- package/build/lib/features/RowSorting.js +0 -226
- package/build/lib/features/RowSorting.js.map +0 -1
- package/build/lib/filterFns.js +0 -96
- package/build/lib/filterFns.js.map +0 -1
- package/build/lib/index.d.ts +0 -34
- package/build/lib/index.esm.js +0 -3522
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.mjs +0 -3522
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/sortingFns.js.map +0 -1
- package/build/lib/utils/filterRowsUtils.js.map +0 -1
- package/build/lib/utils/getCoreRowModel.js +0 -65
- package/build/lib/utils/getCoreRowModel.js.map +0 -1
- package/build/lib/utils/getExpandedRowModel.js +0 -46
- package/build/lib/utils/getExpandedRowModel.js.map +0 -1
- package/build/lib/utils/getFacetedMinMaxValues.js +0 -43
- package/build/lib/utils/getFacetedMinMaxValues.js.map +0 -1
- package/build/lib/utils/getFacetedRowModel.js +0 -36
- package/build/lib/utils/getFacetedUniqueValues.js +0 -39
- package/build/lib/utils/getFacetedUniqueValues.js.map +0 -1
- package/build/lib/utils/getFilteredRowModel.js +0 -111
- package/build/lib/utils/getGroupedRowModel.js +0 -150
- package/build/lib/utils/getGroupedRowModel.js.map +0 -1
- package/build/lib/utils/getPaginationRowModel.js +0 -60
- package/build/lib/utils/getPaginationRowModel.js.map +0 -1
- package/build/lib/utils/getSortedRowModel.js +0 -102
- package/build/umd/index.development.js +0 -3578
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -12
- package/build/umd/index.production.js.map +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { RowModel } from '..';
|
|
2
|
+
import { BuiltInFilterFn } from '../filterFns';
|
|
3
|
+
import { Column, FilterFns, FilterMeta, OnChangeFn, Row, RowData, Table, TableFeature, Updater } from '../types';
|
|
4
|
+
|
|
5
|
+
export interface ColumnFiltersTableState {
|
|
6
|
+
columnFilters: ColumnFiltersState;
|
|
7
|
+
}
|
|
8
|
+
export type ColumnFiltersState = ColumnFilter[];
|
|
9
|
+
export interface ColumnFilter {
|
|
10
|
+
id: string;
|
|
11
|
+
value: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface ResolvedColumnFilter<TData extends RowData> {
|
|
14
|
+
filterFn: FilterFn<TData>;
|
|
15
|
+
id: string;
|
|
16
|
+
resolvedValue: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface FilterFn<TData extends RowData> {
|
|
19
|
+
(row: Row<TData>, columnId: string, filterValue: any, addMeta: (meta: FilterMeta) => void): boolean;
|
|
20
|
+
autoRemove?: ColumnFilterAutoRemoveTestFn<TData>;
|
|
21
|
+
resolveFilterValue?: TransformFilterValueFn<TData>;
|
|
22
|
+
}
|
|
23
|
+
export type TransformFilterValueFn<TData extends RowData> = (value: any, column?: Column<TData, unknown>) => unknown;
|
|
24
|
+
export type ColumnFilterAutoRemoveTestFn<TData extends RowData> = (value: any, column?: Column<TData, unknown>) => boolean;
|
|
25
|
+
export type CustomFilterFns<TData extends RowData> = Record<string, FilterFn<TData>>;
|
|
26
|
+
export type FilterFnOption<TData extends RowData> = 'auto' | BuiltInFilterFn | keyof FilterFns | FilterFn<TData>;
|
|
27
|
+
export interface ColumnFiltersColumnDef<TData extends RowData> {
|
|
28
|
+
/**
|
|
29
|
+
* Enables/disables the **column** filter for this column.
|
|
30
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#enablecolumnfilter)
|
|
31
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
32
|
+
*/
|
|
33
|
+
enableColumnFilter?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The filter function to use with this column. Can be the name of a built-in filter function or a custom filter function.
|
|
36
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#filterfn)
|
|
37
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
38
|
+
*/
|
|
39
|
+
filterFn?: FilterFnOption<TData>;
|
|
40
|
+
}
|
|
41
|
+
export interface ColumnFiltersColumn<TData extends RowData> {
|
|
42
|
+
/**
|
|
43
|
+
* Returns an automatically calculated filter function for the column based off of the columns first known value.
|
|
44
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getautofilterfn)
|
|
45
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
46
|
+
*/
|
|
47
|
+
getAutoFilterFn: () => FilterFn<TData> | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether or not the column can be **column** filtered.
|
|
50
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getcanfilter)
|
|
51
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
52
|
+
*/
|
|
53
|
+
getCanFilter: () => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the filter function (either user-defined or automatic, depending on configuration) for the columnId specified.
|
|
56
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilterfn)
|
|
57
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
58
|
+
*/
|
|
59
|
+
getFilterFn: () => FilterFn<TData> | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the index (including `-1`) of the column filter in the table's `state.columnFilters` array.
|
|
62
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilterindex)
|
|
63
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
64
|
+
*/
|
|
65
|
+
getFilterIndex: () => number;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the current filter value for the column.
|
|
68
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfiltervalue)
|
|
69
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
70
|
+
*/
|
|
71
|
+
getFilterValue: () => unknown;
|
|
72
|
+
/**
|
|
73
|
+
* Returns whether or not the column is currently filtered.
|
|
74
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getisfiltered)
|
|
75
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
76
|
+
*/
|
|
77
|
+
getIsFiltered: () => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* A function that sets the current filter value for the column. You can pass it a value or an updater function for immutability-safe operations on existing values.
|
|
80
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setfiltervalue)
|
|
81
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
82
|
+
*/
|
|
83
|
+
setFilterValue: (updater: Updater<any>) => void;
|
|
84
|
+
}
|
|
85
|
+
export interface ColumnFiltersRow<TData extends RowData> {
|
|
86
|
+
/**
|
|
87
|
+
* The column filters map for the row. This object tracks whether a row is passing/failing specific filters by their column ID.
|
|
88
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#columnfilters)
|
|
89
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
90
|
+
*/
|
|
91
|
+
columnFilters: Record<string, boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* The column filters meta map for the row. This object tracks any filter meta for a row as optionally provided during the filtering process.
|
|
94
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#columnfiltersmeta)
|
|
95
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
96
|
+
*/
|
|
97
|
+
columnFiltersMeta: Record<string, FilterMeta>;
|
|
98
|
+
}
|
|
99
|
+
interface ColumnFiltersOptionsBase<TData extends RowData> {
|
|
100
|
+
/**
|
|
101
|
+
* Enables/disables **column** filtering for all columns.
|
|
102
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#enablecolumnfilters)
|
|
103
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
104
|
+
*/
|
|
105
|
+
enableColumnFilters?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Enables/disables all filtering for the table.
|
|
108
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#enablefilters)
|
|
109
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
110
|
+
*/
|
|
111
|
+
enableFilters?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* By default, filtering is done from parent rows down (so if a parent row is filtered out, all of its children will be filtered out as well). Setting this option to `true` will cause filtering to be done from leaf rows up (which means parent rows will be included so long as one of their child or grand-child rows is also included).
|
|
114
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#filterfromleafrows)
|
|
115
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
116
|
+
*/
|
|
117
|
+
filterFromLeafRows?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* If provided, this function is called **once** per table and should return a **new function** which will calculate and return the row model for the table when it's filtered.
|
|
120
|
+
* - For server-side filtering, this function is unnecessary and can be ignored since the server should already return the filtered row model.
|
|
121
|
+
* - For client-side filtering, this function is required. A default implementation is provided via any table adapter's `{ getFilteredRowModel }` export.
|
|
122
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilteredrowmodel)
|
|
123
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
124
|
+
*/
|
|
125
|
+
getFilteredRowModel?: (table: Table<any>) => () => RowModel<any>;
|
|
126
|
+
/**
|
|
127
|
+
* Disables the `getFilteredRowModel` from being used to filter data. This may be useful if your table needs to dynamically support both client-side and server-side filtering.
|
|
128
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#manualfiltering)
|
|
129
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
130
|
+
*/
|
|
131
|
+
manualFiltering?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* By default, filtering is done for all rows (max depth of 100), no matter if they are root level parent rows or the child leaf rows of a parent row. Setting this option to `0` will cause filtering to only be applied to the root level parent rows, with all sub-rows remaining unfiltered. Similarly, setting this option to `1` will cause filtering to only be applied to child leaf rows 1 level deep, and so on.
|
|
134
|
+
|
|
135
|
+
* This is useful for situations where you want a row's entire child hierarchy to be visible regardless of the applied filter.
|
|
136
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#maxleafrowfilterdepth)
|
|
137
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
138
|
+
*/
|
|
139
|
+
maxLeafRowFilterDepth?: number;
|
|
140
|
+
/**
|
|
141
|
+
* If provided, this function will be called with an `updaterFn` when `state.columnFilters` 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.
|
|
142
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#oncolumnfilterschange)
|
|
143
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
144
|
+
*/
|
|
145
|
+
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>;
|
|
146
|
+
}
|
|
147
|
+
type ResolvedFilterFns = keyof FilterFns extends never ? {
|
|
148
|
+
filterFns?: Record<string, FilterFn<any>>;
|
|
149
|
+
} : {
|
|
150
|
+
filterFns: Record<keyof FilterFns, FilterFn<any>>;
|
|
151
|
+
};
|
|
152
|
+
export interface ColumnFiltersOptions<TData extends RowData> extends ColumnFiltersOptionsBase<TData>, ResolvedFilterFns {
|
|
153
|
+
}
|
|
154
|
+
export interface ColumnFiltersInstance<TData extends RowData> {
|
|
155
|
+
_getFilteredRowModel?: () => RowModel<TData>;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the row model for the table after **column** filtering has been applied.
|
|
158
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getfilteredrowmodel)
|
|
159
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
160
|
+
*/
|
|
161
|
+
getFilteredRowModel: () => RowModel<TData>;
|
|
162
|
+
/**
|
|
163
|
+
* Returns the row model for the table before any **column** filtering has been applied.
|
|
164
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#getprefilteredrowmodel)
|
|
165
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
166
|
+
*/
|
|
167
|
+
getPreFilteredRowModel: () => RowModel<TData>;
|
|
168
|
+
/**
|
|
169
|
+
* Resets the **columnFilters** state to `initialState.columnFilters`, or `true` can be passed to force a default blank state reset to `[]`.
|
|
170
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetcolumnfilters)
|
|
171
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
172
|
+
*/
|
|
173
|
+
resetColumnFilters: (defaultState?: boolean) => void;
|
|
174
|
+
/**
|
|
175
|
+
* Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`.
|
|
176
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#resetglobalfilter)
|
|
177
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
178
|
+
*/
|
|
179
|
+
resetGlobalFilter: (defaultState?: boolean) => void;
|
|
180
|
+
/**
|
|
181
|
+
* Sets or updates the `state.columnFilters` state.
|
|
182
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setcolumnfilters)
|
|
183
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
184
|
+
*/
|
|
185
|
+
setColumnFilters: (updater: Updater<ColumnFiltersState>) => void;
|
|
186
|
+
/**
|
|
187
|
+
* Sets or updates the `state.globalFilter` state.
|
|
188
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#setglobalfilter)
|
|
189
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
|
|
190
|
+
*/
|
|
191
|
+
setGlobalFilter: (updater: Updater<any>) => void;
|
|
192
|
+
}
|
|
193
|
+
export declare const ColumnFiltering: TableFeature;
|
|
194
|
+
export declare function shouldAutoRemoveFilter<TData extends RowData>(filterFn?: FilterFn<TData>, value?: any, column?: Column<TData, unknown>): boolean;
|
|
195
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const aggregationFns = require("../aggregationFns.cjs");
|
|
4
|
+
const utils = require("../utils.cjs");
|
|
5
|
+
const ColumnGrouping = {
|
|
6
|
+
_getDefaultColumnDef: () => {
|
|
7
|
+
return {
|
|
8
|
+
aggregatedCell: (props) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
return ((_b = (_a = props.getValue()) == null ? void 0 : _a.toString) == null ? void 0 : _b.call(_a)) ?? null;
|
|
11
|
+
},
|
|
12
|
+
aggregationFn: "auto"
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
_getInitialState: (state) => {
|
|
16
|
+
return {
|
|
17
|
+
grouping: [],
|
|
18
|
+
...state
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
_getDefaultOptions: (table) => {
|
|
22
|
+
return {
|
|
23
|
+
onGroupingChange: utils.makeStateUpdater("grouping", table),
|
|
24
|
+
groupedColumnMode: "reorder"
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
_createColumn: (column, table) => {
|
|
28
|
+
column.toggleGrouping = () => {
|
|
29
|
+
table.setGrouping((old) => {
|
|
30
|
+
if (old == null ? void 0 : old.includes(column.id)) {
|
|
31
|
+
return old.filter((d) => d !== column.id);
|
|
32
|
+
}
|
|
33
|
+
return [...old ?? [], column.id];
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
column.getCanGroup = () => {
|
|
37
|
+
return (column.columnDef.enableGrouping ?? true) && (table.options.enableGrouping ?? true) && (!!column.accessorFn || !!column.columnDef.getGroupingValue);
|
|
38
|
+
};
|
|
39
|
+
column.getIsGrouped = () => {
|
|
40
|
+
var _a;
|
|
41
|
+
return (_a = table.getState().grouping) == null ? void 0 : _a.includes(column.id);
|
|
42
|
+
};
|
|
43
|
+
column.getGroupedIndex = () => {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = table.getState().grouping) == null ? void 0 : _a.indexOf(column.id);
|
|
46
|
+
};
|
|
47
|
+
column.getToggleGroupingHandler = () => {
|
|
48
|
+
const canGroup = column.getCanGroup();
|
|
49
|
+
return () => {
|
|
50
|
+
if (!canGroup) return;
|
|
51
|
+
column.toggleGrouping();
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
column.getAutoAggregationFn = () => {
|
|
55
|
+
const firstRow = table.getCoreRowModel().flatRows[0];
|
|
56
|
+
const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
|
|
57
|
+
if (typeof value === "number") {
|
|
58
|
+
return aggregationFns.aggregationFns.sum;
|
|
59
|
+
}
|
|
60
|
+
if (Object.prototype.toString.call(value) === "[object Date]") {
|
|
61
|
+
return aggregationFns.aggregationFns.extent;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
column.getAggregationFn = () => {
|
|
65
|
+
var _a;
|
|
66
|
+
if (!column) {
|
|
67
|
+
throw new Error();
|
|
68
|
+
}
|
|
69
|
+
return utils.isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === "auto" ? column.getAutoAggregationFn() : ((_a = table.options.aggregationFns) == null ? void 0 : _a[column.columnDef.aggregationFn]) ?? aggregationFns.aggregationFns[column.columnDef.aggregationFn];
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
_createTable: (table) => {
|
|
73
|
+
table.setGrouping = (updater) => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
return (_b = (_a = table.options).onGroupingChange) == null ? void 0 : _b.call(_a, updater);
|
|
76
|
+
};
|
|
77
|
+
table.resetGrouping = (defaultState) => {
|
|
78
|
+
var _a;
|
|
79
|
+
table.setGrouping(defaultState ? [] : ((_a = table.initialState) == null ? void 0 : _a.grouping) ?? []);
|
|
80
|
+
};
|
|
81
|
+
table.getPreGroupedRowModel = () => table.getFilteredRowModel();
|
|
82
|
+
table.getGroupedRowModel = () => {
|
|
83
|
+
if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
|
|
84
|
+
table._getGroupedRowModel = table.options.getGroupedRowModel(table);
|
|
85
|
+
}
|
|
86
|
+
if (table.options.manualGrouping || !table._getGroupedRowModel) {
|
|
87
|
+
return table.getPreGroupedRowModel();
|
|
88
|
+
}
|
|
89
|
+
return table._getGroupedRowModel();
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
_createRow: (row, table) => {
|
|
93
|
+
row.getIsGrouped = () => !!row.groupingColumnId;
|
|
94
|
+
row.getGroupingValue = (columnId) => {
|
|
95
|
+
if (row._groupingValuesCache.hasOwnProperty(columnId)) {
|
|
96
|
+
return row._groupingValuesCache[columnId];
|
|
97
|
+
}
|
|
98
|
+
const column = table.getColumn(columnId);
|
|
99
|
+
if (!(column == null ? void 0 : column.columnDef.getGroupingValue)) {
|
|
100
|
+
return row.getValue(columnId);
|
|
101
|
+
}
|
|
102
|
+
row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(
|
|
103
|
+
row.original
|
|
104
|
+
);
|
|
105
|
+
return row._groupingValuesCache[columnId];
|
|
106
|
+
};
|
|
107
|
+
row._groupingValuesCache = {};
|
|
108
|
+
},
|
|
109
|
+
_createCell: (cell, column, row, table) => {
|
|
110
|
+
cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
|
|
111
|
+
cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
|
|
112
|
+
cell.getIsAggregated = () => {
|
|
113
|
+
var _a;
|
|
114
|
+
return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_a = row.subRows) == null ? void 0 : _a.length);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
function orderColumns(leafColumns, grouping, groupedColumnMode) {
|
|
119
|
+
if (!(grouping == null ? void 0 : grouping.length) || !groupedColumnMode) {
|
|
120
|
+
return leafColumns;
|
|
121
|
+
}
|
|
122
|
+
const nonGroupingColumns = leafColumns.filter(
|
|
123
|
+
(col) => !grouping.includes(col.id)
|
|
124
|
+
);
|
|
125
|
+
if (groupedColumnMode === "remove") {
|
|
126
|
+
return nonGroupingColumns;
|
|
127
|
+
}
|
|
128
|
+
const groupingColumns = grouping.map((g) => leafColumns.find((col) => col.id === g)).filter(Boolean);
|
|
129
|
+
return [...groupingColumns, ...nonGroupingColumns];
|
|
130
|
+
}
|
|
131
|
+
exports.ColumnGrouping = ColumnGrouping;
|
|
132
|
+
exports.orderColumns = orderColumns;
|
|
133
|
+
//# sourceMappingURL=ColumnGrouping.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnGrouping.cjs","sources":["../../../src/features/ColumnGrouping.ts"],"sourcesContent":["import { RowModel } from '..'\nimport { BuiltInAggregationFn, aggregationFns } from '../aggregationFns'\nimport {\n AggregationFns,\n Cell,\n Column,\n ColumnDefTemplate,\n OnChangeFn,\n Row,\n RowData,\n Table,\n TableFeature,\n Updater,\n} from '../types'\nimport { isFunction, makeStateUpdater } from '../utils'\n\nexport type GroupingState = string[]\n\nexport interface GroupingTableState {\n grouping: GroupingState\n}\n\nexport type AggregationFn<TData extends RowData> = (\n columnId: string,\n leafRows: Row<TData>[],\n childRows: Row<TData>[]\n) => any\n\nexport type CustomAggregationFns = Record<string, AggregationFn<any>>\n\nexport type AggregationFnOption<TData extends RowData> =\n | 'auto'\n | keyof AggregationFns\n | BuiltInAggregationFn\n | AggregationFn<TData>\n\nexport interface GroupingColumnDef<TData extends RowData, TValue> {\n /**\n * The cell to display each row for the column if the cell is an aggregate. If a function is passed, it will be passed a props object with the context of the cell and should return the property type for your adapter (the exact type depends on the adapter being used).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#aggregatedcell)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n aggregatedCell?: ColumnDefTemplate<\n ReturnType<Cell<TData, TValue>['getContext']>\n >\n /**\n * The resolved aggregation function for the column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#aggregationfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n aggregationFn?: AggregationFnOption<TData>\n /**\n * Enables/disables grouping for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#enablegrouping)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n enableGrouping?: boolean\n /**\n * 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.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupingvalue)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getGroupingValue?: (row: TData) => any\n}\n\nexport interface GroupingColumn<TData extends RowData> {\n /**\n * Returns the aggregation function for the column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getaggregationfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getAggregationFn: () => AggregationFn<TData> | undefined\n /**\n * Returns the automatically inferred aggregation function for the column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getautoaggregationfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getAutoAggregationFn: () => AggregationFn<TData> | undefined\n /**\n * Returns whether or not the column can be grouped.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getcangroup)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getCanGroup: () => boolean\n /**\n * Returns the index of the column in the grouping state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getGroupedIndex: () => number\n /**\n * Returns whether or not the column is currently grouped.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisgrouped)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getIsGrouped: () => boolean\n /**\n * Returns a function that toggles the grouping state of the column. This is useful for passing to the `onClick` prop of a button.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#gettogglegroupinghandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getToggleGroupingHandler: () => () => void\n /**\n * Toggles the grouping state of the column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#togglegrouping)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n toggleGrouping: () => void\n}\n\nexport interface GroupingRow {\n _groupingValuesCache: Record<string, any>\n /**\n * Returns the grouping value for any row and column (including leaf rows).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupingvalue)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getGroupingValue: (columnId: string) => unknown\n /**\n * Returns whether or not the row is currently grouped.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisgrouped)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getIsGrouped: () => boolean\n /**\n * If this row is grouped, this is the id of the column that this row is grouped by.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#groupingcolumnid)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n groupingColumnId?: string\n /**\n * If this row is grouped, this is the unique/shared value for the `groupingColumnId` for all of the rows in this group.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#groupingvalue)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n groupingValue?: unknown\n}\n\nexport interface GroupingCell {\n /**\n * Returns whether or not the cell is currently aggregated.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisaggregated)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getIsAggregated: () => boolean\n /**\n * Returns whether or not the cell is currently grouped.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisgrouped)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getIsGrouped: () => boolean\n /**\n * Returns whether or not the cell is currently a placeholder cell.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisplaceholder)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getIsPlaceholder: () => boolean\n}\n\nexport interface ColumnDefaultOptions {\n enableGrouping: boolean\n onGroupingChange: OnChangeFn<GroupingState>\n}\n\ninterface GroupingOptionsBase {\n /**\n * Enables/disables grouping for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#enablegrouping)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n enableGrouping?: boolean\n /**\n * Returns the row model after grouping has taken place, but no further.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getGroupedRowModel?: (table: Table<any>) => () => RowModel<any>\n /**\n * 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.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#groupedcolumnmode)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n groupedColumnMode?: false | 'reorder' | 'remove'\n /**\n * 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.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#manualgrouping)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n manualGrouping?: boolean\n /**\n * 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.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#ongroupingchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n onGroupingChange?: OnChangeFn<GroupingState>\n}\n\ntype ResolvedAggregationFns = keyof AggregationFns extends never\n ? {\n aggregationFns?: Record<string, AggregationFn<any>>\n }\n : {\n aggregationFns: Record<keyof AggregationFns, AggregationFn<any>>\n }\n\nexport interface GroupingOptions\n extends GroupingOptionsBase,\n ResolvedAggregationFns {}\n\nexport type GroupingColumnMode = false | 'reorder' | 'remove'\n\nexport interface GroupingInstance<TData extends RowData> {\n _getGroupedRowModel?: () => RowModel<TData>\n /**\n * Returns the row model for the table after grouping has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getGroupedRowModel: () => RowModel<TData>\n /**\n * Returns the row model for the table before any grouping has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getpregroupedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n getPreGroupedRowModel: () => RowModel<TData>\n /**\n * Resets the **grouping** state to `initialState.grouping`, or `true` can be passed to force a default blank state reset to `[]`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#resetgrouping)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n resetGrouping: (defaultState?: boolean) => void\n /**\n * Updates the grouping state of the table via an update function or value.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#setgrouping)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)\n */\n setGrouping: (updater: Updater<GroupingState>) => void\n}\n\n//\n\nexport const ColumnGrouping: TableFeature = {\n _getDefaultColumnDef: <TData extends RowData>(): GroupingColumnDef<\n TData,\n unknown\n > => {\n return {\n aggregatedCell: props => (props.getValue() as any)?.toString?.() ?? null,\n aggregationFn: 'auto',\n }\n },\n\n _getInitialState: (state): GroupingTableState => {\n return {\n grouping: [],\n ...state,\n }\n },\n\n _getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): GroupingOptions => {\n return {\n onGroupingChange: makeStateUpdater('grouping', table),\n groupedColumnMode: 'reorder',\n }\n },\n\n _createColumn: <TData extends RowData, TValue>(\n column: Column<TData, TValue>,\n table: Table<TData>\n ): void => {\n column.toggleGrouping = () => {\n table.setGrouping(old => {\n // Find any existing grouping for this column\n if (old?.includes(column.id)) {\n return old.filter(d => d !== column.id)\n }\n\n return [...(old ?? []), column.id]\n })\n }\n\n column.getCanGroup = () => {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n }\n\n column.getIsGrouped = () => {\n return table.getState().grouping?.includes(column.id)\n }\n\n column.getGroupedIndex = () => table.getState().grouping?.indexOf(column.id)\n\n column.getToggleGroupingHandler = () => {\n const canGroup = column.getCanGroup()\n\n return () => {\n if (!canGroup) return\n column.toggleGrouping()\n }\n }\n column.getAutoAggregationFn = () => {\n const firstRow = table.getCoreRowModel().flatRows[0]\n\n const value = firstRow?.getValue(column.id)\n\n if (typeof value === 'number') {\n return aggregationFns.sum\n }\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n return aggregationFns.extent\n }\n }\n column.getAggregationFn = () => {\n if (!column) {\n throw new Error()\n }\n\n return isFunction(column.columnDef.aggregationFn)\n ? column.columnDef.aggregationFn\n : column.columnDef.aggregationFn === 'auto'\n ? column.getAutoAggregationFn()\n : table.options.aggregationFns?.[\n column.columnDef.aggregationFn as string\n ] ??\n aggregationFns[\n column.columnDef.aggregationFn as BuiltInAggregationFn\n ]\n }\n },\n\n _createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setGrouping = updater => table.options.onGroupingChange?.(updater)\n\n table.resetGrouping = defaultState => {\n table.setGrouping(defaultState ? [] : table.initialState?.grouping ?? [])\n }\n\n table.getPreGroupedRowModel = () => table.getFilteredRowModel()\n table.getGroupedRowModel = () => {\n if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {\n table._getGroupedRowModel = table.options.getGroupedRowModel(table)\n }\n\n if (table.options.manualGrouping || !table._getGroupedRowModel) {\n return table.getPreGroupedRowModel()\n }\n\n return table._getGroupedRowModel()\n }\n },\n\n _createRow: <TData extends RowData>(\n row: Row<TData>,\n table: Table<TData>\n ): void => {\n row.getIsGrouped = () => !!row.groupingColumnId\n row.getGroupingValue = columnId => {\n if (row._groupingValuesCache.hasOwnProperty(columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = table.getColumn(columnId)\n\n if (!column?.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original\n )\n\n return row._groupingValuesCache[columnId]\n }\n row._groupingValuesCache = {}\n },\n\n _createCell: <TData extends RowData, TValue>(\n cell: Cell<TData, TValue>,\n column: Column<TData, TValue>,\n row: Row<TData>,\n table: Table<TData>\n ): void => {\n const getRenderValue = () =>\n cell.getValue() ?? table.options.renderFallbackValue\n\n cell.getIsGrouped = () =>\n column.getIsGrouped() && column.id === row.groupingColumnId\n cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped()\n cell.getIsAggregated = () =>\n !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!row.subRows?.length\n },\n}\n\nexport function orderColumns<TData extends RowData>(\n leafColumns: Column<TData, unknown>[],\n grouping: string[],\n groupedColumnMode?: GroupingColumnMode\n) {\n if (!grouping?.length || !groupedColumnMode) {\n return leafColumns\n }\n\n const nonGroupingColumns = leafColumns.filter(\n col => !grouping.includes(col.id)\n )\n\n if (groupedColumnMode === 'remove') {\n return nonGroupingColumns\n }\n\n const groupingColumns = grouping\n .map(g => leafColumns.find(col => col.id === g)!)\n .filter(Boolean)\n\n return [...groupingColumns, ...nonGroupingColumns]\n}\n"],"names":["makeStateUpdater","aggregationFns","isFunction"],"mappings":"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"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { RowModel } from '..';
|
|
2
|
+
import { BuiltInAggregationFn } from '../aggregationFns';
|
|
3
|
+
import { AggregationFns, Cell, Column, ColumnDefTemplate, OnChangeFn, Row, RowData, Table, TableFeature, Updater } from '../types';
|
|
4
|
+
|
|
5
|
+
export type GroupingState = string[];
|
|
6
|
+
export interface GroupingTableState {
|
|
7
|
+
grouping: GroupingState;
|
|
8
|
+
}
|
|
9
|
+
export type AggregationFn<TData extends RowData> = (columnId: string, leafRows: Row<TData>[], childRows: Row<TData>[]) => any;
|
|
10
|
+
export type CustomAggregationFns = Record<string, AggregationFn<any>>;
|
|
11
|
+
export type AggregationFnOption<TData extends RowData> = 'auto' | keyof AggregationFns | BuiltInAggregationFn | AggregationFn<TData>;
|
|
12
|
+
export interface GroupingColumnDef<TData extends RowData, TValue> {
|
|
13
|
+
/**
|
|
14
|
+
* The cell to display each row for the column if the cell is an aggregate. If a function is passed, it will be passed a props object with the context of the cell and should return the property type for your adapter (the exact type depends on the adapter being used).
|
|
15
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#aggregatedcell)
|
|
16
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
17
|
+
*/
|
|
18
|
+
aggregatedCell?: ColumnDefTemplate<ReturnType<Cell<TData, TValue>['getContext']>>;
|
|
19
|
+
/**
|
|
20
|
+
* The resolved aggregation function for the column.
|
|
21
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#aggregationfn)
|
|
22
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
23
|
+
*/
|
|
24
|
+
aggregationFn?: AggregationFnOption<TData>;
|
|
25
|
+
/**
|
|
26
|
+
* Enables/disables grouping for this column.
|
|
27
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#enablegrouping)
|
|
28
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
29
|
+
*/
|
|
30
|
+
enableGrouping?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 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.
|
|
33
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupingvalue)
|
|
34
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
35
|
+
*/
|
|
36
|
+
getGroupingValue?: (row: TData) => any;
|
|
37
|
+
}
|
|
38
|
+
export interface GroupingColumn<TData extends RowData> {
|
|
39
|
+
/**
|
|
40
|
+
* Returns the aggregation function for the column.
|
|
41
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getaggregationfn)
|
|
42
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
43
|
+
*/
|
|
44
|
+
getAggregationFn: () => AggregationFn<TData> | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the automatically inferred aggregation function for the column.
|
|
47
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getautoaggregationfn)
|
|
48
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
49
|
+
*/
|
|
50
|
+
getAutoAggregationFn: () => AggregationFn<TData> | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Returns whether or not the column can be grouped.
|
|
53
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getcangroup)
|
|
54
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
55
|
+
*/
|
|
56
|
+
getCanGroup: () => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the index of the column in the grouping state.
|
|
59
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedindex)
|
|
60
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
61
|
+
*/
|
|
62
|
+
getGroupedIndex: () => number;
|
|
63
|
+
/**
|
|
64
|
+
* Returns whether or not the column is currently grouped.
|
|
65
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisgrouped)
|
|
66
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
67
|
+
*/
|
|
68
|
+
getIsGrouped: () => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Returns a function that toggles the grouping state of the column. This is useful for passing to the `onClick` prop of a button.
|
|
71
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#gettogglegroupinghandler)
|
|
72
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
73
|
+
*/
|
|
74
|
+
getToggleGroupingHandler: () => () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Toggles the grouping state of the column.
|
|
77
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#togglegrouping)
|
|
78
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
79
|
+
*/
|
|
80
|
+
toggleGrouping: () => void;
|
|
81
|
+
}
|
|
82
|
+
export interface GroupingRow {
|
|
83
|
+
_groupingValuesCache: Record<string, any>;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the grouping value for any row and column (including leaf rows).
|
|
86
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupingvalue)
|
|
87
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
88
|
+
*/
|
|
89
|
+
getGroupingValue: (columnId: string) => unknown;
|
|
90
|
+
/**
|
|
91
|
+
* Returns whether or not the row is currently grouped.
|
|
92
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisgrouped)
|
|
93
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
94
|
+
*/
|
|
95
|
+
getIsGrouped: () => boolean;
|
|
96
|
+
/**
|
|
97
|
+
* If this row is grouped, this is the id of the column that this row is grouped by.
|
|
98
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#groupingcolumnid)
|
|
99
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
100
|
+
*/
|
|
101
|
+
groupingColumnId?: string;
|
|
102
|
+
/**
|
|
103
|
+
* If this row is grouped, this is the unique/shared value for the `groupingColumnId` for all of the rows in this group.
|
|
104
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#groupingvalue)
|
|
105
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
106
|
+
*/
|
|
107
|
+
groupingValue?: unknown;
|
|
108
|
+
}
|
|
109
|
+
export interface GroupingCell {
|
|
110
|
+
/**
|
|
111
|
+
* Returns whether or not the cell is currently aggregated.
|
|
112
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisaggregated)
|
|
113
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
114
|
+
*/
|
|
115
|
+
getIsAggregated: () => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Returns whether or not the cell is currently grouped.
|
|
118
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisgrouped)
|
|
119
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
120
|
+
*/
|
|
121
|
+
getIsGrouped: () => boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Returns whether or not the cell is currently a placeholder cell.
|
|
124
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getisplaceholder)
|
|
125
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
126
|
+
*/
|
|
127
|
+
getIsPlaceholder: () => boolean;
|
|
128
|
+
}
|
|
129
|
+
export interface ColumnDefaultOptions {
|
|
130
|
+
enableGrouping: boolean;
|
|
131
|
+
onGroupingChange: OnChangeFn<GroupingState>;
|
|
132
|
+
}
|
|
133
|
+
interface GroupingOptionsBase {
|
|
134
|
+
/**
|
|
135
|
+
* Enables/disables grouping for the table.
|
|
136
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#enablegrouping)
|
|
137
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
138
|
+
*/
|
|
139
|
+
enableGrouping?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Returns the row model after grouping has taken place, but no further.
|
|
142
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedrowmodel)
|
|
143
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
144
|
+
*/
|
|
145
|
+
getGroupedRowModel?: (table: Table<any>) => () => RowModel<any>;
|
|
146
|
+
/**
|
|
147
|
+
* 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.
|
|
148
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#groupedcolumnmode)
|
|
149
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
150
|
+
*/
|
|
151
|
+
groupedColumnMode?: false | 'reorder' | 'remove';
|
|
152
|
+
/**
|
|
153
|
+
* 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.
|
|
154
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#manualgrouping)
|
|
155
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
156
|
+
*/
|
|
157
|
+
manualGrouping?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* 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.
|
|
160
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#ongroupingchange)
|
|
161
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
162
|
+
*/
|
|
163
|
+
onGroupingChange?: OnChangeFn<GroupingState>;
|
|
164
|
+
}
|
|
165
|
+
type ResolvedAggregationFns = keyof AggregationFns extends never ? {
|
|
166
|
+
aggregationFns?: Record<string, AggregationFn<any>>;
|
|
167
|
+
} : {
|
|
168
|
+
aggregationFns: Record<keyof AggregationFns, AggregationFn<any>>;
|
|
169
|
+
};
|
|
170
|
+
export interface GroupingOptions extends GroupingOptionsBase, ResolvedAggregationFns {
|
|
171
|
+
}
|
|
172
|
+
export type GroupingColumnMode = false | 'reorder' | 'remove';
|
|
173
|
+
export interface GroupingInstance<TData extends RowData> {
|
|
174
|
+
_getGroupedRowModel?: () => RowModel<TData>;
|
|
175
|
+
/**
|
|
176
|
+
* Returns the row model for the table after grouping has been applied.
|
|
177
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getgroupedrowmodel)
|
|
178
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
179
|
+
*/
|
|
180
|
+
getGroupedRowModel: () => RowModel<TData>;
|
|
181
|
+
/**
|
|
182
|
+
* Returns the row model for the table before any grouping has been applied.
|
|
183
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#getpregroupedrowmodel)
|
|
184
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
185
|
+
*/
|
|
186
|
+
getPreGroupedRowModel: () => RowModel<TData>;
|
|
187
|
+
/**
|
|
188
|
+
* Resets the **grouping** state to `initialState.grouping`, or `true` can be passed to force a default blank state reset to `[]`.
|
|
189
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#resetgrouping)
|
|
190
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
191
|
+
*/
|
|
192
|
+
resetGrouping: (defaultState?: boolean) => void;
|
|
193
|
+
/**
|
|
194
|
+
* Updates the grouping state of the table via an update function or value.
|
|
195
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/grouping#setgrouping)
|
|
196
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/grouping)
|
|
197
|
+
*/
|
|
198
|
+
setGrouping: (updater: Updater<GroupingState>) => void;
|
|
199
|
+
}
|
|
200
|
+
export declare const ColumnGrouping: TableFeature;
|
|
201
|
+
export declare function orderColumns<TData extends RowData>(leafColumns: Column<TData, unknown>[], grouping: string[], groupedColumnMode?: GroupingColumnMode): Column<TData, unknown>[];
|
|
202
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utils = require("../utils.cjs");
|
|
4
|
+
const ColumnGrouping = require("./ColumnGrouping.cjs");
|
|
5
|
+
const ColumnVisibility = require("./ColumnVisibility.cjs");
|
|
6
|
+
const ColumnOrdering = {
|
|
7
|
+
_getInitialState: (state) => {
|
|
8
|
+
return {
|
|
9
|
+
columnOrder: [],
|
|
10
|
+
...state
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
_getDefaultOptions: (table) => {
|
|
14
|
+
return {
|
|
15
|
+
onColumnOrderChange: utils.makeStateUpdater("columnOrder", table)
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
_createColumn: (column, table) => {
|
|
19
|
+
column.getIndex = utils.memo(
|
|
20
|
+
(position) => [ColumnVisibility._getVisibleLeafColumns(table, position)],
|
|
21
|
+
(columns) => columns.findIndex((d) => d.id === column.id),
|
|
22
|
+
utils.getMemoOptions(table.options, "debugColumns", "getIndex")
|
|
23
|
+
);
|
|
24
|
+
column.getIsFirstColumn = (position) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const columns = ColumnVisibility._getVisibleLeafColumns(table, position);
|
|
27
|
+
return ((_a = columns[0]) == null ? void 0 : _a.id) === column.id;
|
|
28
|
+
};
|
|
29
|
+
column.getIsLastColumn = (position) => {
|
|
30
|
+
var _a;
|
|
31
|
+
const columns = ColumnVisibility._getVisibleLeafColumns(table, position);
|
|
32
|
+
return ((_a = columns[columns.length - 1]) == null ? void 0 : _a.id) === column.id;
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
_createTable: (table) => {
|
|
36
|
+
table.setColumnOrder = (updater) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return (_b = (_a = table.options).onColumnOrderChange) == null ? void 0 : _b.call(_a, updater);
|
|
39
|
+
};
|
|
40
|
+
table.resetColumnOrder = (defaultState) => {
|
|
41
|
+
table.setColumnOrder(
|
|
42
|
+
defaultState ? [] : table.initialState.columnOrder ?? []
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
table._getOrderColumnsFn = utils.memo(
|
|
46
|
+
() => [
|
|
47
|
+
table.getState().columnOrder,
|
|
48
|
+
table.getState().grouping,
|
|
49
|
+
table.options.groupedColumnMode
|
|
50
|
+
],
|
|
51
|
+
(columnOrder, grouping, groupedColumnMode) => (columns) => {
|
|
52
|
+
let orderedColumns = [];
|
|
53
|
+
if (!(columnOrder == null ? void 0 : columnOrder.length)) {
|
|
54
|
+
orderedColumns = columns;
|
|
55
|
+
} else {
|
|
56
|
+
const columnOrderCopy = [...columnOrder];
|
|
57
|
+
const columnsCopy = [...columns];
|
|
58
|
+
while (columnsCopy.length && columnOrderCopy.length) {
|
|
59
|
+
const targetColumnId = columnOrderCopy.shift();
|
|
60
|
+
const foundIndex = columnsCopy.findIndex(
|
|
61
|
+
(d) => d.id === targetColumnId
|
|
62
|
+
);
|
|
63
|
+
if (foundIndex > -1) {
|
|
64
|
+
orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
orderedColumns = [...orderedColumns, ...columnsCopy];
|
|
68
|
+
}
|
|
69
|
+
return ColumnGrouping.orderColumns(orderedColumns, grouping, groupedColumnMode);
|
|
70
|
+
},
|
|
71
|
+
utils.getMemoOptions(table.options, "debugTable", "_getOrderColumnsFn")
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.ColumnOrdering = ColumnOrdering;
|
|
76
|
+
//# sourceMappingURL=ColumnOrdering.cjs.map
|