@tanstack/table-core 9.0.0-beta.46 → 9.0.0-beta.48
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/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.cjs +38 -0
- package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
- package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
- package/dist/features/aggregation/aggregationFeature.js +38 -0
- package/dist/features/aggregation/aggregationFeature.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.js +12 -0
- package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
- package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
- package/dist/features/aggregation/aggregationFns.cjs +240 -0
- package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFns.d.cts +67 -0
- package/dist/features/aggregation/aggregationFns.d.ts +67 -0
- package/dist/features/aggregation/aggregationFns.js +229 -0
- package/dist/features/aggregation/aggregationFns.js.map +1 -0
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-filtering/filterFns.cjs +399 -0
- package/dist/features/column-filtering/filterFns.cjs.map +1 -0
- package/dist/features/column-filtering/filterFns.d.cts +210 -0
- package/dist/features/column-filtering/filterFns.d.ts +210 -0
- package/dist/features/column-filtering/filterFns.js +375 -0
- package/dist/features/column-filtering/filterFns.js.map +1 -0
- package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -49
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -49
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -50
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -39
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -39
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -49
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -13
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -3
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -3
- package/dist/features/column-grouping/createGroupedRowModel.js +25 -15
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +32 -3
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +32 -3
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +20 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +20 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.cjs +69 -22
- package/dist/features/row-sorting/sortFns.cjs.map +1 -0
- package/dist/features/row-sorting/sortFns.d.cts +98 -0
- package/dist/features/row-sorting/sortFns.d.ts +98 -0
- package/dist/{fns → features/row-sorting}/sortFns.js +69 -23
- package/dist/features/row-sorting/sortFns.js.map +1 -0
- package/dist/features/stockFeatures.cjs +2 -0
- package/dist/features/stockFeatures.cjs.map +1 -1
- package/dist/features/stockFeatures.d.cts +2 -0
- package/dist/features/stockFeatures.d.ts +2 -0
- package/dist/features/stockFeatures.js +2 -0
- package/dist/features/stockFeatures.js.map +1 -1
- package/dist/helpers/tableFeatures.cjs +5 -4
- package/dist/helpers/tableFeatures.cjs.map +1 -1
- package/dist/helpers/tableFeatures.d.cts +5 -4
- package/dist/helpers/tableFeatures.d.ts +5 -4
- package/dist/helpers/tableFeatures.js +5 -4
- package/dist/helpers/tableFeatures.js.map +1 -1
- package/dist/index.cjs +18 -3
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +6 -4
- package/dist/static-functions.cjs +8 -3
- package/dist/static-functions.d.cts +3 -2
- package/dist/static-functions.d.ts +3 -2
- package/dist/static-functions.js +3 -2
- package/dist/types/Cell.d.cts +3 -1
- package/dist/types/Cell.d.ts +3 -1
- package/dist/types/Column.d.cts +4 -2
- package/dist/types/Column.d.ts +4 -2
- package/dist/types/ColumnDef.d.cts +5 -3
- package/dist/types/ColumnDef.d.ts +5 -3
- package/dist/types/Row.d.cts +3 -1
- package/dist/types/Row.d.ts +3 -1
- package/dist/types/RowModel.d.cts +1 -1
- package/dist/types/RowModel.d.ts +1 -1
- package/dist/types/RowModelFns.d.cts +3 -3
- package/dist/types/RowModelFns.d.ts +3 -3
- package/dist/types/Table.d.cts +1 -1
- package/dist/types/Table.d.ts +1 -1
- package/dist/types/TableFeatures.d.cts +19 -11
- package/dist/types/TableFeatures.d.ts +19 -11
- package/dist/types/TableOptions.d.cts +5 -3
- package/dist/types/TableOptions.d.ts +5 -3
- package/dist/types/TableState.d.cts +1 -1
- package/dist/types/TableState.d.ts +1 -1
- package/dist/types/type-utils.d.cts +8 -1
- package/dist/types/type-utils.d.ts +8 -1
- package/dist/worker/initTableWorker.cjs.map +1 -1
- package/dist/worker/initTableWorker.js.map +1 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +131 -0
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +11 -5
- package/skills/column-filtering/SKILL.md +8 -3
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +3 -3
- package/skills/grouping/SKILL.md +12 -13
- package/skills/migrate-v8-to-v9/SKILL.md +21 -8
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +9 -3
- package/skills/table-features/SKILL.md +19 -13
- package/skills/typescript/SKILL.md +1 -1
- package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
- package/src/features/aggregation/aggregationFeature.ts +59 -0
- package/src/features/aggregation/aggregationFeature.types.ts +312 -0
- package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
- package/src/features/aggregation/aggregationFns.ts +336 -0
- package/src/features/column-filtering/columnFilteringFeature.types.ts +61 -1
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
- package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
- package/src/features/column-filtering/filterFns.ts +533 -0
- package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
- package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -86
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -88
- package/src/features/column-grouping/createGroupedRowModel.ts +32 -38
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +9 -1
- package/src/features/row-sorting/createSortedRowModel.ts +6 -2
- package/src/features/row-sorting/rowSortingFeature.types.ts +54 -2
- package/src/features/row-sorting/rowSortingFeature.utils.ts +46 -14
- package/src/{fns → features/row-sorting}/sortFns.ts +95 -81
- package/src/features/stockFeatures.ts +3 -0
- package/src/helpers/tableFeatures.ts +5 -4
- package/src/index.ts +7 -8
- package/src/static-functions.ts +1 -0
- package/src/types/Cell.ts +2 -0
- package/src/types/Column.ts +3 -1
- package/src/types/ColumnDef.ts +6 -3
- package/src/types/Row.ts +2 -0
- package/src/types/RowModelFns.ts +3 -3
- package/src/types/TableFeatures.ts +19 -11
- package/src/types/TableOptions.ts +5 -1
- package/src/types/type-utils.ts +8 -0
- package/src/worker/initTableWorker.ts +1 -1
- package/dist/fns/aggregationFns.cjs +0 -163
- package/dist/fns/aggregationFns.cjs.map +0 -1
- package/dist/fns/aggregationFns.d.cts +0 -85
- package/dist/fns/aggregationFns.d.ts +0 -85
- package/dist/fns/aggregationFns.js +0 -153
- package/dist/fns/aggregationFns.js.map +0 -1
- package/dist/fns/filterFns.cjs +0 -242
- package/dist/fns/filterFns.cjs.map +0 -1
- package/dist/fns/filterFns.d.cts +0 -178
- package/dist/fns/filterFns.d.ts +0 -178
- package/dist/fns/filterFns.js +0 -226
- package/dist/fns/filterFns.js.map +0 -1
- package/dist/fns/sortFns.cjs.map +0 -1
- package/dist/fns/sortFns.d.cts +0 -65
- package/dist/fns/sortFns.d.ts +0 -65
- package/dist/fns/sortFns.js.map +0 -1
- package/src/fns/aggregationFns.ts +0 -245
- package/src/fns/filterFns.ts +0 -455
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BuiltInAggregationFn } from "../../fns/aggregationFns.cjs";
|
|
3
|
-
import { ColumnDefTemplate } from "../../types/ColumnDef.cjs";
|
|
4
|
-
import { Cell } from "../../types/Cell.cjs";
|
|
1
|
+
import { OnChangeFn, RowData, Updater } from "../../types/type-utils.cjs";
|
|
5
2
|
import { Row } from "../../types/Row.cjs";
|
|
6
3
|
import { RowModel } from "../../core/row-models/coreRowModelsFeature.types.cjs";
|
|
7
|
-
import {
|
|
4
|
+
import { TableFeatures } from "../../types/TableFeatures.cjs";
|
|
8
5
|
|
|
9
6
|
//#region src/features/column-grouping/columnGroupingFeature.types.d.ts
|
|
10
7
|
type GroupingState = Array<string>;
|
|
11
8
|
interface TableState_ColumnGrouping {
|
|
12
9
|
grouping: GroupingState;
|
|
13
10
|
}
|
|
14
|
-
interface
|
|
15
|
-
aggregationFns: Record<string, AggregationFn<TFeatures, TData>>;
|
|
16
|
-
}
|
|
17
|
-
interface AggregationFns {}
|
|
18
|
-
type AggregationFn<TFeatures extends TableFeatures, TData extends RowData> = (columnId: string, leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>) => any;
|
|
19
|
-
type CustomAggregationFns<TFeatures extends TableFeatures, TData extends RowData> = Record<string, AggregationFn<TFeatures, TData>>;
|
|
20
|
-
/**
|
|
21
|
-
* Resolves the valid string names for `columnDef.aggregationFn` for a feature
|
|
22
|
-
* set.
|
|
23
|
-
*
|
|
24
|
-
* When the features object declares an `aggregationFns` registry
|
|
25
|
-
* (`tableFeatures({ ..., aggregationFns })`), its keys are the only valid
|
|
26
|
-
* names; a name is only assignable if an aggregation function is actually
|
|
27
|
-
* registered for it. Otherwise this falls back to the global
|
|
28
|
-
* declaration-merged `AggregationFns` interface.
|
|
29
|
-
*/
|
|
30
|
-
type ExtractAggregationFnKeys<TFeatures extends TableFeatures> = IsAny<TFeatures> extends true ? keyof AggregationFns | BuiltInAggregationFn : TFeatures extends {
|
|
31
|
-
aggregationFns: infer TAggregationFns extends object;
|
|
32
|
-
} ? Extract<keyof TAggregationFns, string> : keyof AggregationFns;
|
|
33
|
-
type AggregationFnOption<TFeatures extends TableFeatures, TData extends RowData> = 'auto' | ExtractAggregationFnKeys<TFeatures> | AggregationFn<TFeatures, TData>;
|
|
34
|
-
interface ColumnDef_ColumnGrouping<in out TFeatures extends TableFeatures, in out TData extends RowData, TValue extends CellData = CellData> {
|
|
35
|
-
/**
|
|
36
|
-
* 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).
|
|
37
|
-
*/
|
|
38
|
-
aggregatedCell?: ColumnDefTemplate<ReturnType<Cell<TFeatures, TData, TValue>['getContext']>>;
|
|
39
|
-
/**
|
|
40
|
-
* The resolved aggregation function for the column.
|
|
41
|
-
*/
|
|
42
|
-
aggregationFn?: AggregationFnOption<TFeatures, TData>;
|
|
11
|
+
interface ColumnDef_ColumnGrouping<in out TFeatures extends TableFeatures, in out TData extends RowData> {
|
|
43
12
|
/**
|
|
44
13
|
* Allows this column to be added to grouping state.
|
|
45
14
|
*
|
|
@@ -54,15 +23,7 @@ interface ColumnDef_ColumnGrouping<in out TFeatures extends TableFeatures, in ou
|
|
|
54
23
|
*/
|
|
55
24
|
getGroupingValue?: (originalRow: TData, index: number, row: Row<TFeatures, TData>) => any;
|
|
56
25
|
}
|
|
57
|
-
interface Column_ColumnGrouping
|
|
58
|
-
/**
|
|
59
|
-
* Returns the aggregation function for the column.
|
|
60
|
-
*/
|
|
61
|
-
getAggregationFn: () => AggregationFn<TFeatures, TData> | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the automatically inferred aggregation function for the column.
|
|
64
|
-
*/
|
|
65
|
-
getAutoAggregationFn: () => AggregationFn<TFeatures, TData> | undefined;
|
|
26
|
+
interface Column_ColumnGrouping {
|
|
66
27
|
/**
|
|
67
28
|
* Checks whether this column can currently be grouped.
|
|
68
29
|
*/
|
|
@@ -104,10 +65,6 @@ interface Row_ColumnGrouping {
|
|
|
104
65
|
groupingValue?: unknown;
|
|
105
66
|
}
|
|
106
67
|
interface Cell_ColumnGrouping {
|
|
107
|
-
/**
|
|
108
|
-
* Checks whether this cell should render an aggregated value.
|
|
109
|
-
*/
|
|
110
|
-
getIsAggregated: () => boolean;
|
|
111
68
|
/**
|
|
112
69
|
* Checks whether this cell represents the active grouping column.
|
|
113
70
|
*/
|
|
@@ -156,7 +113,7 @@ interface Table_ColumnGrouping<in out _TFeatures extends TableFeatures, in out _
|
|
|
156
113
|
}
|
|
157
114
|
interface Table_RowModels_Grouped<in out TFeatures extends TableFeatures, in out TData extends RowData> {
|
|
158
115
|
/**
|
|
159
|
-
* Resolves the row model after grouping
|
|
116
|
+
* Resolves the row model after grouping has been applied.
|
|
160
117
|
*/
|
|
161
118
|
getGroupedRowModel: () => RowModel<TFeatures, TData>;
|
|
162
119
|
/**
|
|
@@ -168,5 +125,5 @@ interface CachedRowModel_Grouped<in out TFeatures extends TableFeatures, in out
|
|
|
168
125
|
groupedRowModel: () => RowModel<TFeatures, TData>;
|
|
169
126
|
}
|
|
170
127
|
//#endregion
|
|
171
|
-
export {
|
|
128
|
+
export { CachedRowModel_Grouped, Cell_ColumnGrouping, ColumnDef_ColumnGrouping, ColumnDefaultOptions, Column_ColumnGrouping, GroupingColumnMode, GroupingState, Row_ColumnGrouping, TableOptions_ColumnGrouping, TableState_ColumnGrouping, Table_ColumnGrouping, Table_RowModels_Grouped };
|
|
172
129
|
//# sourceMappingURL=columnGroupingFeature.types.d.cts.map
|
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BuiltInAggregationFn } from "../../fns/aggregationFns.js";
|
|
3
|
-
import { ColumnDefTemplate } from "../../types/ColumnDef.js";
|
|
4
|
-
import { Cell } from "../../types/Cell.js";
|
|
1
|
+
import { OnChangeFn, RowData, Updater } from "../../types/type-utils.js";
|
|
5
2
|
import { Row } from "../../types/Row.js";
|
|
6
3
|
import { RowModel } from "../../core/row-models/coreRowModelsFeature.types.js";
|
|
7
|
-
import {
|
|
4
|
+
import { TableFeatures } from "../../types/TableFeatures.js";
|
|
8
5
|
|
|
9
6
|
//#region src/features/column-grouping/columnGroupingFeature.types.d.ts
|
|
10
7
|
type GroupingState = Array<string>;
|
|
11
8
|
interface TableState_ColumnGrouping {
|
|
12
9
|
grouping: GroupingState;
|
|
13
10
|
}
|
|
14
|
-
interface
|
|
15
|
-
aggregationFns: Record<string, AggregationFn<TFeatures, TData>>;
|
|
16
|
-
}
|
|
17
|
-
interface AggregationFns {}
|
|
18
|
-
type AggregationFn<TFeatures extends TableFeatures, TData extends RowData> = (columnId: string, leafRows: Array<Row<TFeatures, TData>>, childRows: Array<Row<TFeatures, TData>>) => any;
|
|
19
|
-
type CustomAggregationFns<TFeatures extends TableFeatures, TData extends RowData> = Record<string, AggregationFn<TFeatures, TData>>;
|
|
20
|
-
/**
|
|
21
|
-
* Resolves the valid string names for `columnDef.aggregationFn` for a feature
|
|
22
|
-
* set.
|
|
23
|
-
*
|
|
24
|
-
* When the features object declares an `aggregationFns` registry
|
|
25
|
-
* (`tableFeatures({ ..., aggregationFns })`), its keys are the only valid
|
|
26
|
-
* names; a name is only assignable if an aggregation function is actually
|
|
27
|
-
* registered for it. Otherwise this falls back to the global
|
|
28
|
-
* declaration-merged `AggregationFns` interface.
|
|
29
|
-
*/
|
|
30
|
-
type ExtractAggregationFnKeys<TFeatures extends TableFeatures> = IsAny<TFeatures> extends true ? keyof AggregationFns | BuiltInAggregationFn : TFeatures extends {
|
|
31
|
-
aggregationFns: infer TAggregationFns extends object;
|
|
32
|
-
} ? Extract<keyof TAggregationFns, string> : keyof AggregationFns;
|
|
33
|
-
type AggregationFnOption<TFeatures extends TableFeatures, TData extends RowData> = 'auto' | ExtractAggregationFnKeys<TFeatures> | AggregationFn<TFeatures, TData>;
|
|
34
|
-
interface ColumnDef_ColumnGrouping<in out TFeatures extends TableFeatures, in out TData extends RowData, TValue extends CellData = CellData> {
|
|
35
|
-
/**
|
|
36
|
-
* 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).
|
|
37
|
-
*/
|
|
38
|
-
aggregatedCell?: ColumnDefTemplate<ReturnType<Cell<TFeatures, TData, TValue>['getContext']>>;
|
|
39
|
-
/**
|
|
40
|
-
* The resolved aggregation function for the column.
|
|
41
|
-
*/
|
|
42
|
-
aggregationFn?: AggregationFnOption<TFeatures, TData>;
|
|
11
|
+
interface ColumnDef_ColumnGrouping<in out TFeatures extends TableFeatures, in out TData extends RowData> {
|
|
43
12
|
/**
|
|
44
13
|
* Allows this column to be added to grouping state.
|
|
45
14
|
*
|
|
@@ -54,15 +23,7 @@ interface ColumnDef_ColumnGrouping<in out TFeatures extends TableFeatures, in ou
|
|
|
54
23
|
*/
|
|
55
24
|
getGroupingValue?: (originalRow: TData, index: number, row: Row<TFeatures, TData>) => any;
|
|
56
25
|
}
|
|
57
|
-
interface Column_ColumnGrouping
|
|
58
|
-
/**
|
|
59
|
-
* Returns the aggregation function for the column.
|
|
60
|
-
*/
|
|
61
|
-
getAggregationFn: () => AggregationFn<TFeatures, TData> | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the automatically inferred aggregation function for the column.
|
|
64
|
-
*/
|
|
65
|
-
getAutoAggregationFn: () => AggregationFn<TFeatures, TData> | undefined;
|
|
26
|
+
interface Column_ColumnGrouping {
|
|
66
27
|
/**
|
|
67
28
|
* Checks whether this column can currently be grouped.
|
|
68
29
|
*/
|
|
@@ -104,10 +65,6 @@ interface Row_ColumnGrouping {
|
|
|
104
65
|
groupingValue?: unknown;
|
|
105
66
|
}
|
|
106
67
|
interface Cell_ColumnGrouping {
|
|
107
|
-
/**
|
|
108
|
-
* Checks whether this cell should render an aggregated value.
|
|
109
|
-
*/
|
|
110
|
-
getIsAggregated: () => boolean;
|
|
111
68
|
/**
|
|
112
69
|
* Checks whether this cell represents the active grouping column.
|
|
113
70
|
*/
|
|
@@ -156,7 +113,7 @@ interface Table_ColumnGrouping<in out _TFeatures extends TableFeatures, in out _
|
|
|
156
113
|
}
|
|
157
114
|
interface Table_RowModels_Grouped<in out TFeatures extends TableFeatures, in out TData extends RowData> {
|
|
158
115
|
/**
|
|
159
|
-
* Resolves the row model after grouping
|
|
116
|
+
* Resolves the row model after grouping has been applied.
|
|
160
117
|
*/
|
|
161
118
|
getGroupedRowModel: () => RowModel<TFeatures, TData>;
|
|
162
119
|
/**
|
|
@@ -168,5 +125,5 @@ interface CachedRowModel_Grouped<in out TFeatures extends TableFeatures, in out
|
|
|
168
125
|
groupedRowModel: () => RowModel<TFeatures, TData>;
|
|
169
126
|
}
|
|
170
127
|
//#endregion
|
|
171
|
-
export {
|
|
128
|
+
export { CachedRowModel_Grouped, Cell_ColumnGrouping, ColumnDef_ColumnGrouping, ColumnDefaultOptions, Column_ColumnGrouping, GroupingColumnMode, GroupingState, Row_ColumnGrouping, TableOptions_ColumnGrouping, TableState_ColumnGrouping, Table_ColumnGrouping, Table_RowModels_Grouped };
|
|
172
129
|
//# sourceMappingURL=columnGroupingFeature.types.d.ts.map
|
|
@@ -91,39 +91,6 @@ function column_getToggleGroupingHandler(column) {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Chooses a built-in aggregation function from the first core row value.
|
|
95
|
-
*
|
|
96
|
-
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
97
|
-
* other value types leave aggregation unspecified.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
function column_getAutoAggregationFn(column) {
|
|
105
|
-
const aggregationFns = column.table._rowModelFns.aggregationFns;
|
|
106
|
-
const value = column.table.getCoreRowModel().flatRows[0]?.getValue(column.id);
|
|
107
|
-
if (typeof value === "number") return aggregationFns?.sum;
|
|
108
|
-
if (Object.prototype.toString.call(value) === "[object Date]") return aggregationFns?.extent;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Resolves the aggregation function configured for a column.
|
|
112
|
-
*
|
|
113
|
-
* Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`
|
|
114
|
-
* delegates to `column_getAutoAggregationFn`, and string values are looked up in
|
|
115
|
-
* the table's aggregation function registry.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const aggregationFn = column_getAggregationFn(column)
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
function column_getAggregationFn(column) {
|
|
123
|
-
const aggregationFns = column.table._rowModelFns.aggregationFns;
|
|
124
|
-
return require_utils.isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === "auto" ? column_getAutoAggregationFn(column) : aggregationFns?.[column.columnDef.aggregationFn];
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
94
|
* Routes a grouping updater through the table's grouping change handler.
|
|
128
95
|
*
|
|
129
96
|
* The updater may be a next `GroupingState` array or a function of the previous
|
|
@@ -211,27 +178,10 @@ function cell_getIsGrouped(cell) {
|
|
|
211
178
|
function cell_getIsPlaceholder(cell) {
|
|
212
179
|
return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column);
|
|
213
180
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Checks whether this cell should render an aggregated value.
|
|
216
|
-
*
|
|
217
|
-
* Aggregated cells are non-placeholder, non-grouped cells on rows that have
|
|
218
|
-
* subRows.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* const isAggregated = cell_getIsAggregated(cell)
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
function cell_getIsAggregated(cell) {
|
|
226
|
-
return !cell_getIsGrouped(cell) && !cell_getIsPlaceholder(cell) && !!cell.row.subRows.length;
|
|
227
|
-
}
|
|
228
181
|
|
|
229
182
|
//#endregion
|
|
230
|
-
exports.cell_getIsAggregated = cell_getIsAggregated;
|
|
231
183
|
exports.cell_getIsGrouped = cell_getIsGrouped;
|
|
232
184
|
exports.cell_getIsPlaceholder = cell_getIsPlaceholder;
|
|
233
|
-
exports.column_getAggregationFn = column_getAggregationFn;
|
|
234
|
-
exports.column_getAutoAggregationFn = column_getAutoAggregationFn;
|
|
235
185
|
exports.column_getCanGroup = column_getCanGroup;
|
|
236
186
|
exports.column_getGroupedIndex = column_getGroupedIndex;
|
|
237
187
|
exports.column_getIsGrouped = column_getIsGrouped;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columnGroupingFeature.utils.cjs","names":["isFunction","cloneState","hasOwn"],"sources":["../../../src/features/column-grouping/columnGroupingFeature.utils.ts"],"sourcesContent":["import { cloneState, hasOwn, isFunction } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type {\n AggregationFn,\n GroupingState,\n Row_ColumnGrouping,\n} from './columnGroupingFeature.types'\n\n/**\n * Creates the default grouping state.\n *\n * The feature default is an empty array, meaning no columns are grouped. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const grouping = getDefaultGroupingState()\n * ```\n */\nexport function getDefaultGroupingState(): GroupingState {\n return []\n}\n\n/**\n * Adds or removes this column id from the grouping state.\n *\n * Existing grouped columns keep their order. A column already present in\n * `state.grouping` is removed; otherwise it is appended.\n *\n * @example\n * ```ts\n * column_toggleGrouping(column)\n * ```\n */\nexport function column_toggleGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n table_setGrouping(column.table, (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/**\n * Checks whether this column can be used for grouping.\n *\n * Grouping must be enabled at the column and table level, and the column must\n * either have an accessor or provide `getGroupingValue`.\n *\n * @example\n * ```ts\n * const canGroup = column_getCanGroup(column)\n * ```\n */\nexport function column_getCanGroup<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (column.table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n}\n\n/**\n * Checks whether this column id is present in `state.grouping`.\n *\n * The result only reflects grouping state, not whether the grouped row model has\n * been calculated yet.\n *\n * @example\n * ```ts\n * const isGrouped = column_getIsGrouped(column)\n * ```\n */\nexport function column_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return !!column.table.atoms.grouping?.get()?.includes(column.id)\n}\n\n/**\n * Finds this column's position in the ordered grouping state.\n *\n * The result is `-1` when the column is not grouped.\n *\n * @example\n * ```ts\n * const index = column_getGroupedIndex(column)\n * ```\n */\nexport function column_getGroupedIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1\n}\n\n/**\n * Creates a header/control handler that toggles grouping for this column.\n *\n * The handler is a no-op when `column_getCanGroup(column)` is false.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleGroupingHandler(column)\n * ```\n */\nexport function column_getToggleGroupingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canGroup = column_getCanGroup(column)\n\n return () => {\n if (!canGroup) return\n column_toggleGrouping(column)\n }\n}\n\n/**\n * Chooses a built-in aggregation function from the first core row value.\n *\n * Numeric columns default to `sum`, date-like values default to `extent`, and\n * other value types leave aggregation unspecified.\n *\n * @example\n * ```ts\n * const aggregationFn = column_getAutoAggregationFn(column)\n * ```\n */\nexport function column_getAutoAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n const firstRow = column.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 return undefined\n}\n\n/**\n * Resolves the aggregation function configured for a column.\n *\n * Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`\n * delegates to `column_getAutoAggregationFn`, and string values are looked up in\n * the table's aggregation function registry.\n *\n * @example\n * ```ts\n * const aggregationFn = column_getAggregationFn(column)\n * ```\n */\nexport function column_getAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n return isFunction(column.columnDef.aggregationFn)\n ? column.columnDef.aggregationFn\n : column.columnDef.aggregationFn === 'auto'\n ? column_getAutoAggregationFn(column)\n : aggregationFns?.[column.columnDef.aggregationFn as string]\n}\n\n/**\n * Routes a grouping updater through the table's grouping change handler.\n *\n * The updater may be a next `GroupingState` array or a function of the previous\n * grouping state, matching the instance `table.setGrouping` behavior.\n *\n * @example\n * ```ts\n * table_setGrouping(table, (old) => [...old, 'status'])\n * ```\n */\nexport function table_setGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<GroupingState>) {\n table.options.onGroupingChange?.(updater)\n}\n\n/**\n * Resets `grouping` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.grouping` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetGrouping(table)\n * table_resetGrouping(table, true)\n * ```\n */\nexport function table_resetGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGrouping(\n table,\n defaultState ? [] : cloneState(table.initialState.grouping ?? []),\n )\n}\n\n/**\n * Checks whether this row was created as a grouped row.\n *\n * Grouped rows carry a `groupingColumnId`; ordinary leaf rows do not.\n *\n * @example\n * ```ts\n * const isGrouped = row_getIsGrouped(row)\n * ```\n */\nexport function row_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>) {\n return !!row.groupingColumnId\n}\n\n/**\n * Reads and caches this row's grouping value for a column.\n *\n * `columnDef.getGroupingValue` wins when provided; otherwise the normal row\n * accessor value is used.\n *\n * @example\n * ```ts\n * const groupValue = row_getGroupingValue(row, 'status')\n * ```\n */\nexport function row_getGroupingValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {\n if (row._groupingValuesCache && hasOwn(row._groupingValuesCache, columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId) as Column_Internal<\n TFeatures,\n TData\n >\n\n if (!column.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n if (row._groupingValuesCache) {\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original,\n row.index,\n row,\n )\n }\n\n return row._groupingValuesCache?.[columnId]\n}\n\n/**\n * Checks whether this cell represents the grouped column for a grouped row.\n *\n * This is the cell that usually renders the grouped value and expansion control.\n *\n * @example\n * ```ts\n * const isGroupedCell = cell_getIsGrouped(cell)\n * ```\n */\nexport function cell_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const row = cell.row as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n return (\n column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId\n )\n}\n\n/**\n * Checks whether this cell is a placeholder hidden by grouping.\n *\n * Placeholder cells belong to grouped columns other than the row's active\n * grouping column.\n *\n * @example\n * ```ts\n * const isPlaceholder = cell_getIsPlaceholder(cell)\n * ```\n */\nexport function cell_getIsPlaceholder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)\n}\n\n/**\n * Checks whether this cell should render an aggregated value.\n *\n * Aggregated cells are non-placeholder, non-grouped cells on rows that have\n * subRows.\n *\n * @example\n * ```ts\n * const isAggregated = cell_getIsAggregated(cell)\n * ```\n */\nexport function cell_getIsAggregated<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return (\n !cell_getIsGrouped(cell) &&\n !cell_getIsPlaceholder(cell) &&\n !!cell.row.subRows.length\n )\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"columnGroupingFeature.utils.cjs","names":["cloneState","hasOwn"],"sources":["../../../src/features/column-grouping/columnGroupingFeature.utils.ts"],"sourcesContent":["import { cloneState, hasOwn } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type {\n GroupingState,\n Row_ColumnGrouping,\n} from './columnGroupingFeature.types'\n\n/**\n * Creates the default grouping state.\n *\n * The feature default is an empty array, meaning no columns are grouped. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const grouping = getDefaultGroupingState()\n * ```\n */\nexport function getDefaultGroupingState(): GroupingState {\n return []\n}\n\n/**\n * Adds or removes this column id from the grouping state.\n *\n * Existing grouped columns keep their order. A column already present in\n * `state.grouping` is removed; otherwise it is appended.\n *\n * @example\n * ```ts\n * column_toggleGrouping(column)\n * ```\n */\nexport function column_toggleGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n table_setGrouping(column.table, (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/**\n * Checks whether this column can be used for grouping.\n *\n * Grouping must be enabled at the column and table level, and the column must\n * either have an accessor or provide `getGroupingValue`.\n *\n * @example\n * ```ts\n * const canGroup = column_getCanGroup(column)\n * ```\n */\nexport function column_getCanGroup<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (column.table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n}\n\n/**\n * Checks whether this column id is present in `state.grouping`.\n *\n * The result only reflects grouping state, not whether the grouped row model has\n * been calculated yet.\n *\n * @example\n * ```ts\n * const isGrouped = column_getIsGrouped(column)\n * ```\n */\nexport function column_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return !!column.table.atoms.grouping?.get()?.includes(column.id)\n}\n\n/**\n * Finds this column's position in the ordered grouping state.\n *\n * The result is `-1` when the column is not grouped.\n *\n * @example\n * ```ts\n * const index = column_getGroupedIndex(column)\n * ```\n */\nexport function column_getGroupedIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1\n}\n\n/**\n * Creates a header/control handler that toggles grouping for this column.\n *\n * The handler is a no-op when `column_getCanGroup(column)` is false.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleGroupingHandler(column)\n * ```\n */\nexport function column_getToggleGroupingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canGroup = column_getCanGroup(column)\n\n return () => {\n if (!canGroup) return\n column_toggleGrouping(column)\n }\n}\n\n/**\n * Routes a grouping updater through the table's grouping change handler.\n *\n * The updater may be a next `GroupingState` array or a function of the previous\n * grouping state, matching the instance `table.setGrouping` behavior.\n *\n * @example\n * ```ts\n * table_setGrouping(table, (old) => [...old, 'status'])\n * ```\n */\nexport function table_setGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<GroupingState>) {\n table.options.onGroupingChange?.(updater)\n}\n\n/**\n * Resets `grouping` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.grouping` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetGrouping(table)\n * table_resetGrouping(table, true)\n * ```\n */\nexport function table_resetGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGrouping(\n table,\n defaultState ? [] : cloneState(table.initialState.grouping ?? []),\n )\n}\n\n/**\n * Checks whether this row was created as a grouped row.\n *\n * Grouped rows carry a `groupingColumnId`; ordinary leaf rows do not.\n *\n * @example\n * ```ts\n * const isGrouped = row_getIsGrouped(row)\n * ```\n */\nexport function row_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>) {\n return !!row.groupingColumnId\n}\n\n/**\n * Reads and caches this row's grouping value for a column.\n *\n * `columnDef.getGroupingValue` wins when provided; otherwise the normal row\n * accessor value is used.\n *\n * @example\n * ```ts\n * const groupValue = row_getGroupingValue(row, 'status')\n * ```\n */\nexport function row_getGroupingValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {\n if (row._groupingValuesCache && hasOwn(row._groupingValuesCache, columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId) as Column_Internal<\n TFeatures,\n TData\n >\n\n if (!column.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n if (row._groupingValuesCache) {\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original,\n row.index,\n row,\n )\n }\n\n return row._groupingValuesCache?.[columnId]\n}\n\n/**\n * Checks whether this cell represents the grouped column for a grouped row.\n *\n * This is the cell that usually renders the grouped value and expansion control.\n *\n * @example\n * ```ts\n * const isGroupedCell = cell_getIsGrouped(cell)\n * ```\n */\nexport function cell_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const row = cell.row as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n return (\n column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId\n )\n}\n\n/**\n * Checks whether this cell is a placeholder hidden by grouping.\n *\n * Placeholder cells belong to grouped columns other than the row's active\n * grouping column.\n *\n * @example\n * ```ts\n * const isPlaceholder = cell_getIsPlaceholder(cell)\n * ```\n */\nexport function cell_getIsPlaceholder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAgB,0BAAyC;CACvD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,sBAId,QAAmD;CACnD,kBAAkB,OAAO,QAAQ,QAAQ;EAEvC,IAAI,IAAI,SAAS,OAAO,EAAE,GACxB,OAAO,IAAI,QAAQ,MAAM,MAAM,OAAO,EAAE;EAG1C,OAAO,CAAC,GAAG,KAAK,OAAO,EAAE;CAC3B,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,mBAId,QAAmD;CACnD,QACG,OAAO,UAAU,kBAAkB,UACnC,OAAO,MAAM,QAAQ,kBAAkB,UACvC,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,OAAO,UAAU;AAE/C;;;;;;;;;;;;AAaA,SAAgB,oBAId,QAA4D;CAC5D,OAAO,CAAC,CAAC,OAAO,MAAM,MAAM,UAAU,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE;AACjE;;;;;;;;;;;AAYA,SAAgB,uBAId,QAA2D;CAC3D,OAAO,OAAO,MAAM,MAAM,UAAU,IAAI,CAAC,EAAE,QAAQ,OAAO,EAAE,KAAK;AACnE;;;;;;;;;;;AAYA,SAAgB,gCAId,QAAmD;CACnD,MAAM,WAAW,mBAAmB,MAAM;CAE1C,aAAa;EACX,IAAI,CAAC,UAAU;EACf,sBAAsB,MAAM;CAC9B;AACF;;;;;;;;;;;;AAaA,SAAgB,kBAGd,OAAyC,SAAiC;CAC1E,MAAM,QAAQ,mBAAmB,OAAO;AAC1C;;;;;;;;;;;;;AAcA,SAAgB,oBAGd,OAAyC,cAAwB;CACjE,kBACE,OACA,eAAe,CAAC,IAAIA,yBAAW,MAAM,aAAa,YAAY,CAAC,CAAC,CAClE;AACF;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAA0D;CAC1D,OAAO,CAAC,CAAC,IAAI;AACf;;;;;;;;;;;;AAaA,SAAgB,qBAGd,KAA0D,UAAkB;CAC5E,IAAI,IAAI,wBAAwBC,qBAAO,IAAI,sBAAsB,QAAQ,GACvE,OAAO,IAAI,qBAAqB;CAGlC,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAK3C,IAAI,CAAC,OAAO,UAAU,kBACpB,OAAO,IAAI,SAAS,QAAQ;CAG9B,IAAI,IAAI,sBACN,IAAI,qBAAqB,YAAY,OAAO,UAAU,iBACpD,IAAI,UACJ,IAAI,OACJ,GACF;CAGF,OAAO,IAAI,uBAAuB;AACpC;;;;;;;;;;;AAYA,SAAgB,kBAId,MAAsC;CACtC,MAAM,MAAM,KAAK;CACjB,OACE,oBAAoB,KAAK,MAAM,KAAK,KAAK,OAAO,OAAO,IAAI;AAE/D;;;;;;;;;;;;AAaA,SAAgB,sBAId,MAAsC;CACtC,OAAO,CAAC,kBAAkB,IAAI,KAAK,oBAAoB,KAAK,MAAM;AACpE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CellData, RowData, Updater } from "../../types/type-utils.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { GroupingState, Row_ColumnGrouping } from "./columnGroupingFeature.types.cjs";
|
|
3
3
|
import { Cell } from "../../types/Cell.cjs";
|
|
4
4
|
import { Row } from "../../types/Row.cjs";
|
|
5
5
|
import { Table } from "../../types/Table.cjs";
|
|
@@ -77,31 +77,6 @@ declare function column_getGroupedIndex<TFeatures extends TableFeatures, TData e
|
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
79
|
declare function column_getToggleGroupingHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): () => void;
|
|
80
|
-
/**
|
|
81
|
-
* Chooses a built-in aggregation function from the first core row value.
|
|
82
|
-
*
|
|
83
|
-
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
84
|
-
* other value types leave aggregation unspecified.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
declare function column_getAutoAggregationFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): AggregationFn<TFeatures, TData> | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Resolves the aggregation function configured for a column.
|
|
94
|
-
*
|
|
95
|
-
* Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`
|
|
96
|
-
* delegates to `column_getAutoAggregationFn`, and string values are looked up in
|
|
97
|
-
* the table's aggregation function registry.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* const aggregationFn = column_getAggregationFn(column)
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
declare function column_getAggregationFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): AggregationFn<TFeatures, TData> | undefined;
|
|
105
80
|
/**
|
|
106
81
|
* Routes a grouping updater through the table's grouping change handler.
|
|
107
82
|
*
|
|
@@ -173,18 +148,6 @@ declare function cell_getIsGrouped<TFeatures extends TableFeatures, TData extend
|
|
|
173
148
|
* ```
|
|
174
149
|
*/
|
|
175
150
|
declare function cell_getIsPlaceholder<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
176
|
-
/**
|
|
177
|
-
* Checks whether this cell should render an aggregated value.
|
|
178
|
-
*
|
|
179
|
-
* Aggregated cells are non-placeholder, non-grouped cells on rows that have
|
|
180
|
-
* subRows.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* const isAggregated = cell_getIsAggregated(cell)
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
declare function cell_getIsAggregated<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
188
151
|
//#endregion
|
|
189
|
-
export {
|
|
152
|
+
export { cell_getIsGrouped, cell_getIsPlaceholder, column_getCanGroup, column_getGroupedIndex, column_getIsGrouped, column_getToggleGroupingHandler, column_toggleGrouping, getDefaultGroupingState, row_getGroupingValue, row_getIsGrouped, table_resetGrouping, table_setGrouping };
|
|
190
153
|
//# sourceMappingURL=columnGroupingFeature.utils.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CellData, RowData, Updater } from "../../types/type-utils.js";
|
|
2
|
-
import {
|
|
2
|
+
import { GroupingState, Row_ColumnGrouping } from "./columnGroupingFeature.types.js";
|
|
3
3
|
import { Cell } from "../../types/Cell.js";
|
|
4
4
|
import { Row } from "../../types/Row.js";
|
|
5
5
|
import { Table } from "../../types/Table.js";
|
|
@@ -77,31 +77,6 @@ declare function column_getGroupedIndex<TFeatures extends TableFeatures, TData e
|
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
79
|
declare function column_getToggleGroupingHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): () => void;
|
|
80
|
-
/**
|
|
81
|
-
* Chooses a built-in aggregation function from the first core row value.
|
|
82
|
-
*
|
|
83
|
-
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
84
|
-
* other value types leave aggregation unspecified.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
declare function column_getAutoAggregationFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): AggregationFn<TFeatures, TData> | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Resolves the aggregation function configured for a column.
|
|
94
|
-
*
|
|
95
|
-
* Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`
|
|
96
|
-
* delegates to `column_getAutoAggregationFn`, and string values are looked up in
|
|
97
|
-
* the table's aggregation function registry.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* const aggregationFn = column_getAggregationFn(column)
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
declare function column_getAggregationFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): AggregationFn<TFeatures, TData> | undefined;
|
|
105
80
|
/**
|
|
106
81
|
* Routes a grouping updater through the table's grouping change handler.
|
|
107
82
|
*
|
|
@@ -173,18 +148,6 @@ declare function cell_getIsGrouped<TFeatures extends TableFeatures, TData extend
|
|
|
173
148
|
* ```
|
|
174
149
|
*/
|
|
175
150
|
declare function cell_getIsPlaceholder<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
176
|
-
/**
|
|
177
|
-
* Checks whether this cell should render an aggregated value.
|
|
178
|
-
*
|
|
179
|
-
* Aggregated cells are non-placeholder, non-grouped cells on rows that have
|
|
180
|
-
* subRows.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* const isAggregated = cell_getIsAggregated(cell)
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
declare function cell_getIsAggregated<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
188
151
|
//#endregion
|
|
189
|
-
export {
|
|
152
|
+
export { cell_getIsGrouped, cell_getIsPlaceholder, column_getCanGroup, column_getGroupedIndex, column_getIsGrouped, column_getToggleGroupingHandler, column_toggleGrouping, getDefaultGroupingState, row_getGroupingValue, row_getIsGrouped, table_resetGrouping, table_setGrouping };
|
|
190
153
|
//# sourceMappingURL=columnGroupingFeature.utils.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneState, hasOwn
|
|
1
|
+
import { cloneState, hasOwn } from "../../utils.js";
|
|
2
2
|
|
|
3
3
|
//#region src/features/column-grouping/columnGroupingFeature.utils.ts
|
|
4
4
|
/**
|
|
@@ -91,39 +91,6 @@ function column_getToggleGroupingHandler(column) {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Chooses a built-in aggregation function from the first core row value.
|
|
95
|
-
*
|
|
96
|
-
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
97
|
-
* other value types leave aggregation unspecified.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
function column_getAutoAggregationFn(column) {
|
|
105
|
-
const aggregationFns = column.table._rowModelFns.aggregationFns;
|
|
106
|
-
const value = column.table.getCoreRowModel().flatRows[0]?.getValue(column.id);
|
|
107
|
-
if (typeof value === "number") return aggregationFns?.sum;
|
|
108
|
-
if (Object.prototype.toString.call(value) === "[object Date]") return aggregationFns?.extent;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Resolves the aggregation function configured for a column.
|
|
112
|
-
*
|
|
113
|
-
* Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`
|
|
114
|
-
* delegates to `column_getAutoAggregationFn`, and string values are looked up in
|
|
115
|
-
* the table's aggregation function registry.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const aggregationFn = column_getAggregationFn(column)
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
function column_getAggregationFn(column) {
|
|
123
|
-
const aggregationFns = column.table._rowModelFns.aggregationFns;
|
|
124
|
-
return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === "auto" ? column_getAutoAggregationFn(column) : aggregationFns?.[column.columnDef.aggregationFn];
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
94
|
* Routes a grouping updater through the table's grouping change handler.
|
|
128
95
|
*
|
|
129
96
|
* The updater may be a next `GroupingState` array or a function of the previous
|
|
@@ -211,21 +178,7 @@ function cell_getIsGrouped(cell) {
|
|
|
211
178
|
function cell_getIsPlaceholder(cell) {
|
|
212
179
|
return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column);
|
|
213
180
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Checks whether this cell should render an aggregated value.
|
|
216
|
-
*
|
|
217
|
-
* Aggregated cells are non-placeholder, non-grouped cells on rows that have
|
|
218
|
-
* subRows.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* const isAggregated = cell_getIsAggregated(cell)
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
function cell_getIsAggregated(cell) {
|
|
226
|
-
return !cell_getIsGrouped(cell) && !cell_getIsPlaceholder(cell) && !!cell.row.subRows.length;
|
|
227
|
-
}
|
|
228
181
|
|
|
229
182
|
//#endregion
|
|
230
|
-
export {
|
|
183
|
+
export { cell_getIsGrouped, cell_getIsPlaceholder, column_getCanGroup, column_getGroupedIndex, column_getIsGrouped, column_getToggleGroupingHandler, column_toggleGrouping, getDefaultGroupingState, row_getGroupingValue, row_getIsGrouped, table_resetGrouping, table_setGrouping };
|
|
231
184
|
//# sourceMappingURL=columnGroupingFeature.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columnGroupingFeature.utils.js","names":[],"sources":["../../../src/features/column-grouping/columnGroupingFeature.utils.ts"],"sourcesContent":["import { cloneState, hasOwn, isFunction } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type {\n AggregationFn,\n GroupingState,\n Row_ColumnGrouping,\n} from './columnGroupingFeature.types'\n\n/**\n * Creates the default grouping state.\n *\n * The feature default is an empty array, meaning no columns are grouped. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const grouping = getDefaultGroupingState()\n * ```\n */\nexport function getDefaultGroupingState(): GroupingState {\n return []\n}\n\n/**\n * Adds or removes this column id from the grouping state.\n *\n * Existing grouped columns keep their order. A column already present in\n * `state.grouping` is removed; otherwise it is appended.\n *\n * @example\n * ```ts\n * column_toggleGrouping(column)\n * ```\n */\nexport function column_toggleGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n table_setGrouping(column.table, (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/**\n * Checks whether this column can be used for grouping.\n *\n * Grouping must be enabled at the column and table level, and the column must\n * either have an accessor or provide `getGroupingValue`.\n *\n * @example\n * ```ts\n * const canGroup = column_getCanGroup(column)\n * ```\n */\nexport function column_getCanGroup<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (column.table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n}\n\n/**\n * Checks whether this column id is present in `state.grouping`.\n *\n * The result only reflects grouping state, not whether the grouped row model has\n * been calculated yet.\n *\n * @example\n * ```ts\n * const isGrouped = column_getIsGrouped(column)\n * ```\n */\nexport function column_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return !!column.table.atoms.grouping?.get()?.includes(column.id)\n}\n\n/**\n * Finds this column's position in the ordered grouping state.\n *\n * The result is `-1` when the column is not grouped.\n *\n * @example\n * ```ts\n * const index = column_getGroupedIndex(column)\n * ```\n */\nexport function column_getGroupedIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1\n}\n\n/**\n * Creates a header/control handler that toggles grouping for this column.\n *\n * The handler is a no-op when `column_getCanGroup(column)` is false.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleGroupingHandler(column)\n * ```\n */\nexport function column_getToggleGroupingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canGroup = column_getCanGroup(column)\n\n return () => {\n if (!canGroup) return\n column_toggleGrouping(column)\n }\n}\n\n/**\n * Chooses a built-in aggregation function from the first core row value.\n *\n * Numeric columns default to `sum`, date-like values default to `extent`, and\n * other value types leave aggregation unspecified.\n *\n * @example\n * ```ts\n * const aggregationFn = column_getAutoAggregationFn(column)\n * ```\n */\nexport function column_getAutoAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n const firstRow = column.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 return undefined\n}\n\n/**\n * Resolves the aggregation function configured for a column.\n *\n * Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`\n * delegates to `column_getAutoAggregationFn`, and string values are looked up in\n * the table's aggregation function registry.\n *\n * @example\n * ```ts\n * const aggregationFn = column_getAggregationFn(column)\n * ```\n */\nexport function column_getAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n return isFunction(column.columnDef.aggregationFn)\n ? column.columnDef.aggregationFn\n : column.columnDef.aggregationFn === 'auto'\n ? column_getAutoAggregationFn(column)\n : aggregationFns?.[column.columnDef.aggregationFn as string]\n}\n\n/**\n * Routes a grouping updater through the table's grouping change handler.\n *\n * The updater may be a next `GroupingState` array or a function of the previous\n * grouping state, matching the instance `table.setGrouping` behavior.\n *\n * @example\n * ```ts\n * table_setGrouping(table, (old) => [...old, 'status'])\n * ```\n */\nexport function table_setGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<GroupingState>) {\n table.options.onGroupingChange?.(updater)\n}\n\n/**\n * Resets `grouping` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.grouping` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetGrouping(table)\n * table_resetGrouping(table, true)\n * ```\n */\nexport function table_resetGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGrouping(\n table,\n defaultState ? [] : cloneState(table.initialState.grouping ?? []),\n )\n}\n\n/**\n * Checks whether this row was created as a grouped row.\n *\n * Grouped rows carry a `groupingColumnId`; ordinary leaf rows do not.\n *\n * @example\n * ```ts\n * const isGrouped = row_getIsGrouped(row)\n * ```\n */\nexport function row_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>) {\n return !!row.groupingColumnId\n}\n\n/**\n * Reads and caches this row's grouping value for a column.\n *\n * `columnDef.getGroupingValue` wins when provided; otherwise the normal row\n * accessor value is used.\n *\n * @example\n * ```ts\n * const groupValue = row_getGroupingValue(row, 'status')\n * ```\n */\nexport function row_getGroupingValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {\n if (row._groupingValuesCache && hasOwn(row._groupingValuesCache, columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId) as Column_Internal<\n TFeatures,\n TData\n >\n\n if (!column.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n if (row._groupingValuesCache) {\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original,\n row.index,\n row,\n )\n }\n\n return row._groupingValuesCache?.[columnId]\n}\n\n/**\n * Checks whether this cell represents the grouped column for a grouped row.\n *\n * This is the cell that usually renders the grouped value and expansion control.\n *\n * @example\n * ```ts\n * const isGroupedCell = cell_getIsGrouped(cell)\n * ```\n */\nexport function cell_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const row = cell.row as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n return (\n column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId\n )\n}\n\n/**\n * Checks whether this cell is a placeholder hidden by grouping.\n *\n * Placeholder cells belong to grouped columns other than the row's active\n * grouping column.\n *\n * @example\n * ```ts\n * const isPlaceholder = cell_getIsPlaceholder(cell)\n * ```\n */\nexport function cell_getIsPlaceholder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)\n}\n\n/**\n * Checks whether this cell should render an aggregated value.\n *\n * Aggregated cells are non-placeholder, non-grouped cells on rows that have\n * subRows.\n *\n * @example\n * ```ts\n * const isAggregated = cell_getIsAggregated(cell)\n * ```\n */\nexport function cell_getIsAggregated<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return (\n !cell_getIsGrouped(cell) &&\n !cell_getIsPlaceholder(cell) &&\n !!cell.row.subRows.length\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAgB,0BAAyC;CACvD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,sBAId,QAAmD;CACnD,kBAAkB,OAAO,QAAQ,QAAQ;EAEvC,IAAI,IAAI,SAAS,OAAO,EAAE,GACxB,OAAO,IAAI,QAAQ,MAAM,MAAM,OAAO,EAAE;EAG1C,OAAO,CAAC,GAAG,KAAK,OAAO,EAAE;CAC3B,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,mBAId,QAAmD;CACnD,QACG,OAAO,UAAU,kBAAkB,UACnC,OAAO,MAAM,QAAQ,kBAAkB,UACvC,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,OAAO,UAAU;AAE/C;;;;;;;;;;;;AAaA,SAAgB,oBAId,QAA4D;CAC5D,OAAO,CAAC,CAAC,OAAO,MAAM,MAAM,UAAU,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE;AACjE;;;;;;;;;;;AAYA,SAAgB,uBAId,QAA2D;CAC3D,OAAO,OAAO,MAAM,MAAM,UAAU,IAAI,CAAC,EAAE,QAAQ,OAAO,EAAE,KAAK;AACnE;;;;;;;;;;;AAYA,SAAgB,gCAId,QAAmD;CACnD,MAAM,WAAW,mBAAmB,MAAM;CAE1C,aAAa;EACX,IAAI,CAAC,UAAU;EACf,sBAAsB,MAAM;CAC9B;AACF;;;;;;;;;;;;AAaA,SAAgB,4BAId,QAAmD;CACnD,MAAM,iBAEU,OAAO,MAAM,aAAa;CAI1C,MAAM,QAFW,OAAO,MAAM,gBAAgB,CAAC,CAAC,SAAS,EAEnC,EAAE,SAAS,OAAO,EAAE;CAE1C,IAAI,OAAO,UAAU,UACnB,OAAO,gBAAgB;CAGzB,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,iBAC5C,OAAO,gBAAgB;AAI3B;;;;;;;;;;;;;AAcA,SAAgB,wBAId,QAAmD;CACnD,MAAM,iBAEU,OAAO,MAAM,aAAa;CAE1C,OAAO,WAAW,OAAO,UAAU,aAAa,IAC5C,OAAO,UAAU,gBACjB,OAAO,UAAU,kBAAkB,SACjC,4BAA4B,MAAM,IAClC,iBAAiB,OAAO,UAAU;AAC1C;;;;;;;;;;;;AAaA,SAAgB,kBAGd,OAAyC,SAAiC;CAC1E,MAAM,QAAQ,mBAAmB,OAAO;AAC1C;;;;;;;;;;;;;AAcA,SAAgB,oBAGd,OAAyC,cAAwB;CACjE,kBACE,OACA,eAAe,CAAC,IAAI,WAAW,MAAM,aAAa,YAAY,CAAC,CAAC,CAClE;AACF;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAA0D;CAC1D,OAAO,CAAC,CAAC,IAAI;AACf;;;;;;;;;;;;AAaA,SAAgB,qBAGd,KAA0D,UAAkB;CAC5E,IAAI,IAAI,wBAAwB,OAAO,IAAI,sBAAsB,QAAQ,GACvE,OAAO,IAAI,qBAAqB;CAGlC,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAK3C,IAAI,CAAC,OAAO,UAAU,kBACpB,OAAO,IAAI,SAAS,QAAQ;CAG9B,IAAI,IAAI,sBACN,IAAI,qBAAqB,YAAY,OAAO,UAAU,iBACpD,IAAI,UACJ,IAAI,OACJ,GACF;CAGF,OAAO,IAAI,uBAAuB;AACpC;;;;;;;;;;;AAYA,SAAgB,kBAId,MAAsC;CACtC,MAAM,MAAM,KAAK;CACjB,OACE,oBAAoB,KAAK,MAAM,KAAK,KAAK,OAAO,OAAO,IAAI;AAE/D;;;;;;;;;;;;AAaA,SAAgB,sBAId,MAAsC;CACtC,OAAO,CAAC,kBAAkB,IAAI,KAAK,oBAAoB,KAAK,MAAM;AACpE;;;;;;;;;;;;AAaA,SAAgB,qBAId,MAAsC;CACtC,OACE,CAAC,kBAAkB,IAAI,KACvB,CAAC,sBAAsB,IAAI,KAC3B,CAAC,CAAC,KAAK,IAAI,QAAQ;AAEvB"}
|
|
1
|
+
{"version":3,"file":"columnGroupingFeature.utils.js","names":[],"sources":["../../../src/features/column-grouping/columnGroupingFeature.utils.ts"],"sourcesContent":["import { cloneState, hasOwn } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type {\n GroupingState,\n Row_ColumnGrouping,\n} from './columnGroupingFeature.types'\n\n/**\n * Creates the default grouping state.\n *\n * The feature default is an empty array, meaning no columns are grouped. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const grouping = getDefaultGroupingState()\n * ```\n */\nexport function getDefaultGroupingState(): GroupingState {\n return []\n}\n\n/**\n * Adds or removes this column id from the grouping state.\n *\n * Existing grouped columns keep their order. A column already present in\n * `state.grouping` is removed; otherwise it is appended.\n *\n * @example\n * ```ts\n * column_toggleGrouping(column)\n * ```\n */\nexport function column_toggleGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n table_setGrouping(column.table, (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/**\n * Checks whether this column can be used for grouping.\n *\n * Grouping must be enabled at the column and table level, and the column must\n * either have an accessor or provide `getGroupingValue`.\n *\n * @example\n * ```ts\n * const canGroup = column_getCanGroup(column)\n * ```\n */\nexport function column_getCanGroup<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (column.table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n}\n\n/**\n * Checks whether this column id is present in `state.grouping`.\n *\n * The result only reflects grouping state, not whether the grouped row model has\n * been calculated yet.\n *\n * @example\n * ```ts\n * const isGrouped = column_getIsGrouped(column)\n * ```\n */\nexport function column_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return !!column.table.atoms.grouping?.get()?.includes(column.id)\n}\n\n/**\n * Finds this column's position in the ordered grouping state.\n *\n * The result is `-1` when the column is not grouped.\n *\n * @example\n * ```ts\n * const index = column_getGroupedIndex(column)\n * ```\n */\nexport function column_getGroupedIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1\n}\n\n/**\n * Creates a header/control handler that toggles grouping for this column.\n *\n * The handler is a no-op when `column_getCanGroup(column)` is false.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleGroupingHandler(column)\n * ```\n */\nexport function column_getToggleGroupingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canGroup = column_getCanGroup(column)\n\n return () => {\n if (!canGroup) return\n column_toggleGrouping(column)\n }\n}\n\n/**\n * Routes a grouping updater through the table's grouping change handler.\n *\n * The updater may be a next `GroupingState` array or a function of the previous\n * grouping state, matching the instance `table.setGrouping` behavior.\n *\n * @example\n * ```ts\n * table_setGrouping(table, (old) => [...old, 'status'])\n * ```\n */\nexport function table_setGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<GroupingState>) {\n table.options.onGroupingChange?.(updater)\n}\n\n/**\n * Resets `grouping` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.grouping` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetGrouping(table)\n * table_resetGrouping(table, true)\n * ```\n */\nexport function table_resetGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGrouping(\n table,\n defaultState ? [] : cloneState(table.initialState.grouping ?? []),\n )\n}\n\n/**\n * Checks whether this row was created as a grouped row.\n *\n * Grouped rows carry a `groupingColumnId`; ordinary leaf rows do not.\n *\n * @example\n * ```ts\n * const isGrouped = row_getIsGrouped(row)\n * ```\n */\nexport function row_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>) {\n return !!row.groupingColumnId\n}\n\n/**\n * Reads and caches this row's grouping value for a column.\n *\n * `columnDef.getGroupingValue` wins when provided; otherwise the normal row\n * accessor value is used.\n *\n * @example\n * ```ts\n * const groupValue = row_getGroupingValue(row, 'status')\n * ```\n */\nexport function row_getGroupingValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {\n if (row._groupingValuesCache && hasOwn(row._groupingValuesCache, columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId) as Column_Internal<\n TFeatures,\n TData\n >\n\n if (!column.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n if (row._groupingValuesCache) {\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original,\n row.index,\n row,\n )\n }\n\n return row._groupingValuesCache?.[columnId]\n}\n\n/**\n * Checks whether this cell represents the grouped column for a grouped row.\n *\n * This is the cell that usually renders the grouped value and expansion control.\n *\n * @example\n * ```ts\n * const isGroupedCell = cell_getIsGrouped(cell)\n * ```\n */\nexport function cell_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const row = cell.row as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n return (\n column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId\n )\n}\n\n/**\n * Checks whether this cell is a placeholder hidden by grouping.\n *\n * Placeholder cells belong to grouped columns other than the row's active\n * grouping column.\n *\n * @example\n * ```ts\n * const isPlaceholder = cell_getIsPlaceholder(cell)\n * ```\n */\nexport function cell_getIsPlaceholder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAgB,0BAAyC;CACvD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,sBAId,QAAmD;CACnD,kBAAkB,OAAO,QAAQ,QAAQ;EAEvC,IAAI,IAAI,SAAS,OAAO,EAAE,GACxB,OAAO,IAAI,QAAQ,MAAM,MAAM,OAAO,EAAE;EAG1C,OAAO,CAAC,GAAG,KAAK,OAAO,EAAE;CAC3B,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,mBAId,QAAmD;CACnD,QACG,OAAO,UAAU,kBAAkB,UACnC,OAAO,MAAM,QAAQ,kBAAkB,UACvC,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,OAAO,UAAU;AAE/C;;;;;;;;;;;;AAaA,SAAgB,oBAId,QAA4D;CAC5D,OAAO,CAAC,CAAC,OAAO,MAAM,MAAM,UAAU,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE;AACjE;;;;;;;;;;;AAYA,SAAgB,uBAId,QAA2D;CAC3D,OAAO,OAAO,MAAM,MAAM,UAAU,IAAI,CAAC,EAAE,QAAQ,OAAO,EAAE,KAAK;AACnE;;;;;;;;;;;AAYA,SAAgB,gCAId,QAAmD;CACnD,MAAM,WAAW,mBAAmB,MAAM;CAE1C,aAAa;EACX,IAAI,CAAC,UAAU;EACf,sBAAsB,MAAM;CAC9B;AACF;;;;;;;;;;;;AAaA,SAAgB,kBAGd,OAAyC,SAAiC;CAC1E,MAAM,QAAQ,mBAAmB,OAAO;AAC1C;;;;;;;;;;;;;AAcA,SAAgB,oBAGd,OAAyC,cAAwB;CACjE,kBACE,OACA,eAAe,CAAC,IAAI,WAAW,MAAM,aAAa,YAAY,CAAC,CAAC,CAClE;AACF;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAA0D;CAC1D,OAAO,CAAC,CAAC,IAAI;AACf;;;;;;;;;;;;AAaA,SAAgB,qBAGd,KAA0D,UAAkB;CAC5E,IAAI,IAAI,wBAAwB,OAAO,IAAI,sBAAsB,QAAQ,GACvE,OAAO,IAAI,qBAAqB;CAGlC,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAK3C,IAAI,CAAC,OAAO,UAAU,kBACpB,OAAO,IAAI,SAAS,QAAQ;CAG9B,IAAI,IAAI,sBACN,IAAI,qBAAqB,YAAY,OAAO,UAAU,iBACpD,IAAI,UACJ,IAAI,OACJ,GACF;CAGF,OAAO,IAAI,uBAAuB;AACpC;;;;;;;;;;;AAYA,SAAgB,kBAId,MAAsC;CACtC,MAAM,MAAM,KAAK;CACjB,OACE,oBAAoB,KAAK,MAAM,KAAK,KAAK,OAAO,OAAO,IAAI;AAE/D;;;;;;;;;;;;AAaA,SAAgB,sBAId,MAAsC;CACtC,OAAO,CAAC,kBAAkB,IAAI,KAAK,oBAAoB,KAAK,MAAM;AACpE"}
|
|
@@ -2,6 +2,7 @@ const require_utils = require('../../utils.cjs');
|
|
|
2
2
|
const require_coreColumnsFeature_utils = require('../../core/columns/coreColumnsFeature.utils.cjs');
|
|
3
3
|
const require_constructRow = require('../../core/rows/constructRow.cjs');
|
|
4
4
|
const require_rowPaginationFeature_utils = require('../row-pagination/rowPaginationFeature.utils.cjs');
|
|
5
|
+
const require_aggregationFeature_utils = require('../aggregation/aggregationFeature.utils.cjs');
|
|
5
6
|
const require_columnGroupingFeature_utils = require('./columnGroupingFeature.utils.cjs');
|
|
6
7
|
const require_rowExpandingFeature_utils = require('../row-expanding/rowExpandingFeature.utils.cjs');
|
|
7
8
|
|
|
@@ -11,9 +12,8 @@ const require_rowExpandingFeature_utils = require('../row-expanding/rowExpanding
|
|
|
11
12
|
*
|
|
12
13
|
* The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.
|
|
15
|
+
* When aggregationFeature is also registered, grouped rows use its shared
|
|
16
|
+
* executor for non-group values. Grouping remains useful without aggregation.
|
|
17
17
|
*/
|
|
18
18
|
function createGroupedRowModel() {
|
|
19
19
|
return (_table) => {
|
|
@@ -22,7 +22,11 @@ function createGroupedRowModel() {
|
|
|
22
22
|
feature: "columnGroupingFeature",
|
|
23
23
|
table,
|
|
24
24
|
fnName: "table.getGroupedRowModel",
|
|
25
|
-
memoDeps: () => [
|
|
25
|
+
memoDeps: () => [
|
|
26
|
+
table.atoms.grouping?.get(),
|
|
27
|
+
table.getPreGroupedRowModel(),
|
|
28
|
+
table.options.columns
|
|
29
|
+
],
|
|
26
30
|
fn: () => _createGroupedRowModel(table),
|
|
27
31
|
onAfterUpdate: () => {
|
|
28
32
|
require_rowExpandingFeature_utils.table_autoResetExpanded(table);
|
|
@@ -66,7 +70,7 @@ function _createGroupedRowModel(table) {
|
|
|
66
70
|
subRows.forEach((subRow) => {
|
|
67
71
|
subRow.parentId = id;
|
|
68
72
|
});
|
|
69
|
-
const leafRows =
|
|
73
|
+
const leafRows = require_aggregationFeature_utils.normalizeAggregationRows(groupedRows);
|
|
70
74
|
const row = require_constructRow.constructRow(table, id, leafRows[0].original, index, depth, void 0, parentId);
|
|
71
75
|
Object.assign(row, {
|
|
72
76
|
groupingColumnId: columnId,
|
|
@@ -74,18 +78,24 @@ function _createGroupedRowModel(table) {
|
|
|
74
78
|
subRows,
|
|
75
79
|
leafRows,
|
|
76
80
|
getValue: (colId) => {
|
|
77
|
-
|
|
81
|
+
const groupingIndex = existingGrouping.indexOf(colId);
|
|
82
|
+
if (groupingIndex !== -1 && groupingIndex <= depth) {
|
|
78
83
|
if (require_utils.hasOwn(row._valuesCache, colId)) return row._valuesCache[colId];
|
|
79
84
|
if (groupedRows[0]) row._valuesCache[colId] = groupedRows[0].getValue(colId) ?? void 0;
|
|
80
85
|
return row._valuesCache[colId];
|
|
81
86
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const aggregationCache = row._aggregationValuesCache;
|
|
88
|
+
if (aggregationCache && require_utils.hasOwn(aggregationCache, colId)) return aggregationCache[colId];
|
|
89
|
+
const column = table.getColumn(colId);
|
|
90
|
+
if (typeof column.getAggregationFns !== "function") return void 0;
|
|
91
|
+
const cache = row._aggregationValuesCache ??= require_utils.makeObjectMap();
|
|
92
|
+
cache[colId] = require_aggregationFeature_utils.aggregateColumnValue({
|
|
93
|
+
childRows: subRows,
|
|
94
|
+
column,
|
|
95
|
+
groupingRow: row,
|
|
96
|
+
rows: leafRows
|
|
97
|
+
});
|
|
98
|
+
return cache[colId];
|
|
89
99
|
}
|
|
90
100
|
});
|
|
91
101
|
subRows.forEach((subRow) => {
|