@adaptabletools/adaptable-cjs 20.0.5 → 20.0.7-canary.0

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.
Files changed (37) hide show
  1. package/base.css +20 -0
  2. package/base.css.map +1 -1
  3. package/index.css +16 -0
  4. package/index.css.map +1 -1
  5. package/package.json +1 -1
  6. package/src/AdaptableOptions/ColumnOptions.d.ts +173 -2
  7. package/src/AdaptableState/Common/AggregationColumns.d.ts +8 -1
  8. package/src/AdaptableState/LayoutState.d.ts +12 -0
  9. package/src/Api/Implementation/ColumnApiImpl.d.ts +1 -0
  10. package/src/Api/Implementation/ColumnApiImpl.js +13 -2
  11. package/src/Api/Implementation/LayoutHelpers.js +25 -2
  12. package/src/Api/Internal/ColumnInternalApi.d.ts +3 -1
  13. package/src/Api/Internal/ColumnInternalApi.js +201 -0
  14. package/src/Utilities/Constants/GeneralConstants.d.ts +1 -0
  15. package/src/Utilities/Constants/GeneralConstants.js +3 -2
  16. package/src/Utilities/Extensions/StringExtensions.js +11 -3
  17. package/src/Utilities/adaptableOverrideCheck.d.ts +2 -0
  18. package/src/Utilities/adaptableOverrideCheck.js +13 -0
  19. package/src/agGrid/AdaptableAgGrid.js +29 -0
  20. package/src/agGrid/AgGridAdapter.js +1 -0
  21. package/src/agGrid/AgGridColumnAdapter.d.ts +1 -1
  22. package/src/agGrid/AgGridColumnAdapter.js +6 -12
  23. package/src/components/Select/Select.js +3 -3
  24. package/src/env.js +2 -2
  25. package/src/layout-manager/src/LayoutManagerModel.d.ts +23 -20
  26. package/src/layout-manager/src/destructurePivotColumnId.d.ts +10 -0
  27. package/src/layout-manager/src/destructurePivotColumnId.js +84 -0
  28. package/src/layout-manager/src/index.d.ts +5 -0
  29. package/src/layout-manager/src/index.js +167 -1
  30. package/src/layout-manager/src/isPivotGroupTotalColumn.d.ts +2 -0
  31. package/src/layout-manager/src/isPivotGroupTotalColumn.js +9 -0
  32. package/src/layout-manager/src/isPivotTotalColumn.d.ts +2 -0
  33. package/src/layout-manager/src/isPivotTotalColumn.js +7 -0
  34. package/src/layout-manager/src/normalizeLayoutModel.js +3 -0
  35. package/src/metamodel/adaptable.metamodel.d.ts +12 -4
  36. package/src/metamodel/adaptable.metamodel.js +1 -1
  37. package/tsconfig.cjs.tsbuildinfo +1 -1
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.destructurePivotColumnId = void 0;
4
+ // supports only pivotTotalColumns (aggregation total) and pivotGroupTotal
5
+ // AG Grid builds the ID as: `pivot_${pivotCols.join('-')}_${pivotKeys.join('-')}_${measureColumnId}`
6
+ // see https://github.com/ag-grid/ag-grid/blob/e0cfe533b55b75cdc148cdfb1a4e977731dc0712/packages/ag-grid-enterprise/src/pivot/pivotColDefService.ts#L454C16-L454C88
7
+ function destructurePivotColumnId(colDef, currentModel, logWarning) {
8
+ const { colId } = colDef;
9
+ // Basic validation
10
+ if (!colId?.startsWith('pivot_')) {
11
+ logWarning(`Column id must start with 'pivot_': ${colId}`);
12
+ return '!unknown!';
13
+ }
14
+ const hasSpecialChars = (arr) => arr.some((str) => str.includes('-') || str.includes('_'));
15
+ // AG Grid uses _ and - as delimiters
16
+ // if we have these special characters in the column IDs, we need to parse them differently
17
+ const colIdsOrKeysContainSpecialChars = hasSpecialChars(currentModel.pivotColIds) ||
18
+ hasSpecialChars(currentModel.aggColIds) ||
19
+ hasSpecialChars(colDef.pivotKeys || []);
20
+ // Fast path - no special characters
21
+ if (!colIdsOrKeysContainSpecialChars) {
22
+ // Split by underscore to get 4 parts
23
+ const parts = colId.split('_');
24
+ if (parts.length !== 4) {
25
+ logWarning(`Unsupported format of pivot total column id: ${colId}`);
26
+ return '!unknown!';
27
+ }
28
+ const [_pivotPrefix, pivotColsTxt, pivotKeysTxt, aggregationColumnId] = parts;
29
+ const pivotColumnIds = pivotColsTxt.split('-');
30
+ const pivotKeys = pivotKeysTxt.split('-');
31
+ const pivotColumnId = pivotColumnIds[pivotKeys.length - 1];
32
+ return {
33
+ pivotColumnIds,
34
+ pivotKeys,
35
+ pivotColumnId,
36
+ aggregationColumnId: aggregationColumnId !== '' ? aggregationColumnId : undefined,
37
+ };
38
+ }
39
+ // the complex path, where we have to handle the special characters
40
+ // Remove 'pivot_' prefix
41
+ const withoutPrefix = colId.slice(6);
42
+ // Check if it's a pivot group total
43
+ const isPivotGroupTotal = withoutPrefix.endsWith('_');
44
+ // Get pivot keys from colDef (more reliable than string parsing)
45
+ const pivotKeys = colDef.pivotKeys || [];
46
+ if (isPivotGroupTotal) {
47
+ // Remove trailing underscore for pivot group totals
48
+ const content = withoutPrefix.slice(0, -1);
49
+ // The remaining content should be the pivot columns
50
+ const pivotColumnIds = currentModel.pivotColIds.filter((id) => content.includes(id));
51
+ if (!pivotColumnIds.length) {
52
+ logWarning(`Could not identify pivot columns in: ${content}`);
53
+ return '!unknown!';
54
+ }
55
+ return {
56
+ pivotColumnIds,
57
+ pivotKeys,
58
+ pivotColumnId: pivotColumnIds[pivotKeys.length],
59
+ };
60
+ }
61
+ // For regular pivot columns, work backwards to find aggregation column
62
+ const parts = withoutPrefix.split('_');
63
+ const lastPart = parts[parts.length - 1];
64
+ // Find the longest matching aggregation column id from the end
65
+ const aggregationColumnId = currentModel.aggColIds.find((aggId) => lastPart.endsWith(aggId));
66
+ if (!aggregationColumnId) {
67
+ logWarning(`Could not identify aggregation column in: ${lastPart}`);
68
+ return '!unknown!';
69
+ }
70
+ // Remove aggregation part and get pivot columns
71
+ const withoutAgg = withoutPrefix.slice(0, -(aggregationColumnId.length + 1));
72
+ const pivotColumnIds = currentModel.pivotColIds.filter((id) => withoutAgg.includes(id));
73
+ if (!pivotColumnIds.length) {
74
+ logWarning(`Could not identify pivot columns in: ${withoutAgg}`);
75
+ return '!unknown!';
76
+ }
77
+ return {
78
+ pivotColumnIds,
79
+ pivotKeys,
80
+ pivotColumnId: pivotColumnIds[pivotKeys.length - 1],
81
+ aggregationColumnId,
82
+ };
83
+ }
84
+ exports.destructurePivotColumnId = destructurePivotColumnId;
@@ -69,7 +69,12 @@ export declare class LayoutManager<DATA_TYPE = any> extends LMEmitter {
69
69
  private computeColumnOrderAndVisibility;
70
70
  autoSizeColumns(columnIds?: string[]): false | string[];
71
71
  private applyPivotLayout;
72
+ applyPivotTotals(layout: PivotLayoutModel): void;
72
73
  applyPivotExpandLevel(layout: PivotLayoutModel): void;
73
74
  private withSuppressColumnAnimation;
75
+ private setupPivotTotals;
76
+ private isPivotRowTotalColDef;
77
+ private patchPivotTotalColumn;
78
+ private getPivotTotalColumnConfig;
74
79
  }
75
80
  export {};
@@ -8,6 +8,8 @@ const normalizeLayoutModel_1 = require("./normalizeLayoutModel");
8
8
  const isLayoutEqual_1 = require("./isLayoutEqual");
9
9
  const simplifyLayoutModel_1 = require("./simplifyLayoutModel");
10
10
  const sortColumnIdsByOrder_1 = require("./sortColumnIdsByOrder");
11
+ const destructurePivotColumnId_1 = require("./destructurePivotColumnId");
12
+ const isPivotTotalColumn_1 = require("./isPivotTotalColumn");
11
13
  function flattenColDefs(colDefs) {
12
14
  const res = [];
13
15
  const iteration = (c) => {
@@ -120,8 +122,12 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
120
122
  }).bind(this);
121
123
  }
122
124
  this.setOptions(options);
125
+ // this ensures the grand total columns are positioned correctly (before/after) even when changed at runtime
126
+ // see https://www.ag-grid.com/react-data-grid/pivoting-column-groups/#changing-data-filters-and-configurations
127
+ this.gridApi.setGridOption('enableStrictPivotColumnOrder', true);
123
128
  this.setupEvents();
124
129
  this.indexColumns();
130
+ this.setupPivotTotals();
125
131
  globalThis.layoutManager = this;
126
132
  }
127
133
  destroy() {
@@ -255,6 +261,18 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
255
261
  PivotAggregationColumns: layout.TableAggregationColumns,
256
262
  PivotExpandLevel: prevLayout?.PivotExpandLevel ?? -1,
257
263
  };
264
+ const grandTotalRow = this.gridApi.getGridOption('grandTotalRow');
265
+ if (grandTotalRow) {
266
+ pivotLayout.GrandTotalRow = grandTotalRow;
267
+ }
268
+ const grandTotalColumn = this.gridApi.getGridOption('pivotRowTotals');
269
+ if (grandTotalColumn) {
270
+ pivotLayout.GrandTotalColumn = grandTotalColumn;
271
+ }
272
+ const pivotGroupTotalColumn = this.gridApi.getGridOption('pivotColumnGroupTotals');
273
+ if (pivotGroupTotalColumn) {
274
+ pivotLayout.PivotGroupTotalColumn = pivotGroupTotalColumn;
275
+ }
258
276
  return (0, simplifyLayoutModel_1.simplifyPivotLayoutModel)(pivotLayout);
259
277
  }
260
278
  getTableLayoutModelFromGrid() {
@@ -275,7 +293,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
275
293
  let ColumnPinning = {};
276
294
  const gridState = this.gridApi.getState();
277
295
  const prevLayout = this.currentLayout;
278
- const prevAggColumns = prevLayout?.TableAggregationColumns;
296
+ const prevAggColumns = prevLayout?.TableAggregationColumns ?? prevLayout?.PivotAggregationColumns;
279
297
  const prevAggColumnsMap = prevAggColumns?.reduce((acc, agg) => {
280
298
  acc[agg.ColumnId] = agg;
281
299
  return acc;
@@ -986,6 +1004,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
986
1004
  return columnIds;
987
1005
  }
988
1006
  applyPivotLayout(layout, options) {
1007
+ this.applyPivotTotals(layout);
989
1008
  const columnState = this.computeColumnStateForPivotLayout(layout);
990
1009
  // by simply calling this.gridApi.applyColumnState(columnState)
991
1010
  // the order of aggregations is not preserved/guaranteed by ag-grid
@@ -1013,6 +1032,50 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1013
1032
  this.applyRowGroupValues(layout.RowGroupValues);
1014
1033
  }
1015
1034
  }
1035
+ applyPivotTotals(layout) {
1036
+ /**
1037
+ * GrandTotalRow
1038
+ */
1039
+ if (layout.GrandTotalRow) {
1040
+ const grandTotalRow = layout.GrandTotalRow === true || layout.GrandTotalRow === 'top'
1041
+ ? 'top'
1042
+ : layout.GrandTotalRow === 'bottom'
1043
+ ? 'bottom'
1044
+ : null;
1045
+ this.gridApi.setGridOption('grandTotalRow', grandTotalRow);
1046
+ }
1047
+ else {
1048
+ this.gridApi.setGridOption('grandTotalRow', null);
1049
+ }
1050
+ /**
1051
+ * GrandTotalColumn
1052
+ */
1053
+ if (layout.GrandTotalColumn) {
1054
+ const grandTotalColumn = layout.GrandTotalColumn === true || layout.GrandTotalColumn === 'before'
1055
+ ? 'before'
1056
+ : layout.GrandTotalColumn === 'after'
1057
+ ? 'after'
1058
+ : null;
1059
+ this.gridApi.setGridOption('pivotRowTotals', grandTotalColumn);
1060
+ }
1061
+ else {
1062
+ this.gridApi.setGridOption('pivotRowTotals', null);
1063
+ }
1064
+ /**
1065
+ * PivotGroupTotalColumn
1066
+ */
1067
+ if (layout.PivotGroupTotalColumn) {
1068
+ const pivotGroupTotalColumn = layout.PivotGroupTotalColumn === true || layout.PivotGroupTotalColumn === 'before'
1069
+ ? 'before'
1070
+ : layout.PivotGroupTotalColumn === 'after'
1071
+ ? 'after'
1072
+ : null;
1073
+ this.gridApi.setGridOption('pivotColumnGroupTotals', pivotGroupTotalColumn);
1074
+ }
1075
+ else {
1076
+ this.gridApi.setGridOption('pivotColumnGroupTotals', null);
1077
+ }
1078
+ }
1016
1079
  applyPivotExpandLevel(layout) {
1017
1080
  const PivotExpandLevel = layout.PivotExpandLevel ?? -1;
1018
1081
  const allDisplayedColumnGroups = this.gridApi.getAllDisplayedColumnGroups();
@@ -1048,5 +1111,108 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1048
1111
  }
1049
1112
  return res;
1050
1113
  }
1114
+ setupPivotTotals() {
1115
+ const _original_processPivotResultColDef = this.gridApi.getGridOption('processPivotResultColDef');
1116
+ const _original_processPivotResultColGroupDef = this.gridApi.getGridOption('processPivotResultColGroupDef');
1117
+ this.gridApi.setGridOption('processPivotResultColGroupDef', (colGroupDef) => {
1118
+ _original_processPivotResultColGroupDef?.(colGroupDef);
1119
+ if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout)) {
1120
+ return;
1121
+ }
1122
+ this.patchPivotTotalColumn(colGroupDef);
1123
+ });
1124
+ }
1125
+ isPivotRowTotalColDef(colDef) {
1126
+ return colDef.colId?.startsWith('PivotRowTotal_');
1127
+ }
1128
+ patchPivotTotalColumn(colGroupDef) {
1129
+ const hasPivotTotalCols = (pivotLayout) => {
1130
+ return pivotLayout.PivotAggregationColumns?.some((aggCol) => !!aggCol.TotalColumn);
1131
+ };
1132
+ if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout) || !hasPivotTotalCols(this.currentLayout)) {
1133
+ return;
1134
+ }
1135
+ const pivotRowTotalColDefsBefore = [];
1136
+ const pivotRowTotalColDefsAfter = [];
1137
+ const pivotTotalColDefsBefore = [];
1138
+ const pivotTotalColDefsAfter = [];
1139
+ const normalColDefs = [];
1140
+ colGroupDef.children.forEach((colDef) => {
1141
+ if (this.isPivotRowTotalColDef(colDef)) {
1142
+ if (this.gridApi.getGridOption('pivotRowTotals') === 'after') {
1143
+ pivotRowTotalColDefsAfter.push(colDef);
1144
+ }
1145
+ else {
1146
+ pivotRowTotalColDefsBefore.push(colDef);
1147
+ }
1148
+ return;
1149
+ }
1150
+ if ((0, isPivotTotalColumn_1.isPivotTotalColumn)(colDef)) {
1151
+ if (!colDef.colId.startsWith('pivot_')) {
1152
+ this.warn(`Pivot total column ${colDef.colId} is not prefixed with 'pivot_', skipping...`);
1153
+ return;
1154
+ }
1155
+ // we do this for all total cols, but we will hide the ones that are not visible
1156
+ colDef.columnGroupShow = undefined;
1157
+ const totalColConfig = this.getPivotTotalColumnConfig(colDef, this.currentLayout);
1158
+ if (!totalColConfig.visible) {
1159
+ colDef.hide = true;
1160
+ }
1161
+ else {
1162
+ if (totalColConfig.position === 'after') {
1163
+ pivotTotalColDefsAfter.push(colDef);
1164
+ }
1165
+ else {
1166
+ pivotTotalColDefsBefore.push(colDef);
1167
+ }
1168
+ }
1169
+ }
1170
+ else {
1171
+ normalColDefs.push(colDef);
1172
+ }
1173
+ });
1174
+ colGroupDef.children = [
1175
+ ...pivotRowTotalColDefsBefore,
1176
+ ...pivotTotalColDefsBefore,
1177
+ ...normalColDefs,
1178
+ ...pivotTotalColDefsAfter,
1179
+ ...pivotRowTotalColDefsAfter,
1180
+ ];
1181
+ }
1182
+ getPivotTotalColumnConfig(colDef, currentPivotLayout) {
1183
+ const defaultHiddenConfig = {
1184
+ visible: false,
1185
+ };
1186
+ const colIdInfo = (0, destructurePivotColumnId_1.destructurePivotColumnId)(colDef, {
1187
+ pivotColIds: this.currentLayout.PivotColumns,
1188
+ aggColIds: this.currentLayout.PivotAggregationColumns.map((col) => col.ColumnId),
1189
+ }, (message) => this.warn(message));
1190
+ if (colIdInfo === '!unknown!') {
1191
+ return defaultHiddenConfig;
1192
+ }
1193
+ const { pivotColumnId, aggregationColumnId } = colIdInfo;
1194
+ const layoutAggCol = currentPivotLayout.PivotAggregationColumns?.find((col) => col.ColumnId === aggregationColumnId);
1195
+ if (!layoutAggCol) {
1196
+ this.warn(`Pivot Totals: could NOT find aggregation(value) column with id ${aggregationColumnId}`);
1197
+ return defaultHiddenConfig;
1198
+ }
1199
+ const layoutPivotTotalColumn = layoutAggCol.TotalColumn;
1200
+ if (!layoutPivotTotalColumn) {
1201
+ return defaultHiddenConfig;
1202
+ }
1203
+ if (Array.isArray(layoutPivotTotalColumn)) {
1204
+ const pivotSpecificConfig = layoutPivotTotalColumn.find((config) => config.PivotColumnId === pivotColumnId);
1205
+ return {
1206
+ visible: pivotSpecificConfig && pivotSpecificConfig.ShowTotal !== false,
1207
+ position: pivotSpecificConfig?.ShowTotal === 'after' ? 'after' : 'before',
1208
+ };
1209
+ }
1210
+ else {
1211
+ return {
1212
+ visible: !!layoutPivotTotalColumn,
1213
+ position: layoutPivotTotalColumn === 'after' ? 'after' : 'before',
1214
+ };
1215
+ }
1216
+ }
1051
1217
  }
1052
1218
  exports.LayoutManager = LayoutManager;
@@ -0,0 +1,2 @@
1
+ import { ColDef } from 'ag-grid-enterprise';
2
+ export declare function isPivotGroupTotalColumn(colDef: ColDef): boolean;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPivotGroupTotalColumn = void 0;
4
+ function isPivotGroupTotalColumn(colDef) {
5
+ // pivot group total are spanning cross all aggregations
6
+ // therefore the last part of the colId is empty (hence the "dangling" underscore)
7
+ return colDef.colId?.startsWith('pivot_') && colDef.colId?.endsWith('_');
8
+ }
9
+ exports.isPivotGroupTotalColumn = isPivotGroupTotalColumn;
@@ -0,0 +1,2 @@
1
+ import { ColDef } from 'ag-grid-enterprise';
2
+ export declare function isPivotTotalColumn(colDef: ColDef): colDef is ColDef;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPivotTotalColumn = void 0;
4
+ function isPivotTotalColumn(colDef) {
5
+ return !!colDef.pivotTotalColumnIds?.length;
6
+ }
7
+ exports.isPivotTotalColumn = isPivotTotalColumn;
@@ -144,6 +144,9 @@ function normalizePivotLayoutModel(layout) {
144
144
  // make it an own property
145
145
  layout.SuppressAggFuncInHeader = undefined;
146
146
  }
147
+ if (!layout.GrandTotalRow) {
148
+ layout.GrandTotalRow = false;
149
+ }
147
150
  return layout;
148
151
  }
149
152
  exports.normalizePivotLayoutModel = normalizePivotLayoutModel;
@@ -2011,6 +2011,14 @@ export declare const ADAPTABLE_METAMODEL: {
2011
2011
  defVal: string;
2012
2012
  gridInfo?: undefined;
2013
2013
  noCode?: undefined;
2014
+ } | {
2015
+ name: string;
2016
+ kind: string;
2017
+ desc: string;
2018
+ isOpt: boolean;
2019
+ gridInfo?: undefined;
2020
+ noCode?: undefined;
2021
+ defVal?: undefined;
2014
2022
  })[];
2015
2023
  };
2016
2024
  ColumnScope: {
@@ -4368,18 +4376,18 @@ export declare const ADAPTABLE_METAMODEL: {
4368
4376
  kind: string;
4369
4377
  desc: string;
4370
4378
  isOpt: boolean;
4371
- ref: string;
4379
+ ref?: undefined;
4372
4380
  } | {
4373
4381
  name: string;
4374
4382
  kind: string;
4375
4383
  desc: string;
4376
- isOpt?: undefined;
4377
- ref?: undefined;
4384
+ isOpt: boolean;
4385
+ ref: string;
4378
4386
  } | {
4379
4387
  name: string;
4380
4388
  kind: string;
4381
4389
  desc: string;
4382
- isOpt: boolean;
4390
+ isOpt?: undefined;
4383
4391
  ref?: undefined;
4384
4392
  })[];
4385
4393
  };