@adaptabletools/adaptable-cjs 20.0.6 → 20.0.7-canary.1

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 (32) hide show
  1. package/package.json +1 -1
  2. package/src/AdaptableOptions/ColumnOptions.d.ts +173 -2
  3. package/src/AdaptableState/Common/AggregationColumns.d.ts +8 -1
  4. package/src/AdaptableState/LayoutState.d.ts +12 -0
  5. package/src/Api/Implementation/ColumnApiImpl.d.ts +1 -0
  6. package/src/Api/Implementation/ColumnApiImpl.js +13 -2
  7. package/src/Api/Implementation/LayoutHelpers.js +25 -2
  8. package/src/Api/Internal/ColumnInternalApi.d.ts +3 -1
  9. package/src/Api/Internal/ColumnInternalApi.js +201 -0
  10. package/src/Utilities/Constants/GeneralConstants.d.ts +1 -0
  11. package/src/Utilities/Constants/GeneralConstants.js +3 -2
  12. package/src/Utilities/Extensions/StringExtensions.js +11 -3
  13. package/src/Utilities/adaptableOverrideCheck.d.ts +2 -0
  14. package/src/Utilities/adaptableOverrideCheck.js +13 -0
  15. package/src/agGrid/AdaptableAgGrid.js +29 -0
  16. package/src/agGrid/AgGridAdapter.js +1 -0
  17. package/src/agGrid/AgGridColumnAdapter.d.ts +1 -1
  18. package/src/agGrid/AgGridColumnAdapter.js +6 -12
  19. package/src/env.js +2 -2
  20. package/src/layout-manager/src/LayoutManagerModel.d.ts +23 -20
  21. package/src/layout-manager/src/destructurePivotColumnId.d.ts +10 -0
  22. package/src/layout-manager/src/destructurePivotColumnId.js +84 -0
  23. package/src/layout-manager/src/index.d.ts +5 -0
  24. package/src/layout-manager/src/index.js +167 -1
  25. package/src/layout-manager/src/isPivotGroupTotalColumn.d.ts +2 -0
  26. package/src/layout-manager/src/isPivotGroupTotalColumn.js +9 -0
  27. package/src/layout-manager/src/isPivotTotalColumn.d.ts +2 -0
  28. package/src/layout-manager/src/isPivotTotalColumn.js +7 -0
  29. package/src/layout-manager/src/normalizeLayoutModel.js +3 -0
  30. package/src/metamodel/adaptable.metamodel.d.ts +12 -4
  31. package/src/metamodel/adaptable.metamodel.js +1 -1
  32. package/tsconfig.cjs.tsbuildinfo +1 -1
@@ -101,6 +101,7 @@ const AdaptableColumn_1 = require("../AdaptableState/Common/AdaptableColumn");
101
101
  const agGridDataTypeDefinitions_1 = require("./agGridDataTypeDefinitions");
102
102
  const AgGridThemeAdapter_1 = require("./AgGridThemeAdapter");
103
103
  const VersionUpgrade20_1 = require("../migration/VersionUpgrade20");
104
+ const adaptableOverrideCheck_1 = require("../Utilities/adaptableOverrideCheck");
104
105
  const LocalEventService_Prototype = ag_grid_enterprise_1.LocalEventService.prototype;
105
106
  const LocalEventService_dispatchEvent = LocalEventService_Prototype.dispatchEvent;
106
107
  LocalEventService_Prototype.dispatchEvent = function (event) {
@@ -614,6 +615,34 @@ You need to define at least one Layout!`);
614
615
  this.agGridAdapter.setAgGridId(agGridId);
615
616
  return agGridId;
616
617
  });
618
+ /**
619
+ * `defaultColDef`
620
+ */
621
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'defaultColDef', (original_defaultColDef) => {
622
+ if (original_defaultColDef?.headerValueGetter) {
623
+ this.logger.warn(`defaultColDef.headerValueGetter and overrides the Adaptable custom header mechanism! We recommend using a ColumnOptions.tableColumnHeader instead!`);
624
+ return original_defaultColDef;
625
+ }
626
+ const defaultColDef = { ...original_defaultColDef };
627
+ defaultColDef.headerValueGetter = (0, adaptableOverrideCheck_1.tagProvidedByAdaptable)((params) => {
628
+ return this.api.columnApi.internalApi.getColumnHeaderName(params);
629
+ });
630
+ return defaultColDef;
631
+ });
632
+ /**
633
+ * `defaultColGroupDef`
634
+ */
635
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'defaultColGroupDef', (original_defaultColGroupDef) => {
636
+ if (original_defaultColGroupDef?.headerValueGetter) {
637
+ this.logger.warn(`defaultColGroupDef.headerValueGetter and overrides the Adaptable custom header mechanism! We recommend using a ColumnOptions.tableColumnHeader instead!`);
638
+ return original_defaultColGroupDef;
639
+ }
640
+ const defaultColGroupDef = { ...original_defaultColGroupDef };
641
+ defaultColGroupDef.headerValueGetter = (0, adaptableOverrideCheck_1.tagProvidedByAdaptable)((params) => {
642
+ return this.api.columnApi.internalApi.getColumnHeaderName(params);
643
+ });
644
+ return defaultColGroupDef;
645
+ });
617
646
  /**
618
647
  * `theme`
619
648
  */
@@ -378,6 +378,7 @@ class AgGridAdapter {
378
378
  agColumn: agGridColumn,
379
379
  columnGroup: isRealColumnGroup ? ColumnGroup : undefined,
380
380
  displayName: displayName,
381
+ ...this.adaptableApi.internalApi.buildBaseContext(),
381
382
  })
382
383
  : null;
383
384
  friendlyName =
@@ -27,7 +27,7 @@ export declare class AgGridColumnAdapter {
27
27
  private setupColumnAllowedAggFuncs;
28
28
  private setupColumnType;
29
29
  private setupColumnCellDataType;
30
- setupColumnHeader({ col, abColumn }: ColumnSetupInfo): boolean;
30
+ setupColumnHeader({ col, abColumn }: ColumnSetupInfo): void;
31
31
  private setupColumnFilter;
32
32
  setupColumnFloatingFilterTemporarily(initialGridOptions: GridOptions): void;
33
33
  private setupColumnFloatingFilter;
@@ -17,6 +17,7 @@ const AdaptableNumberEditor_1 = require("./editors/AdaptableNumberEditor");
17
17
  const AdaptableDateEditor_1 = require("./editors/AdaptableDateEditor");
18
18
  const AgGridExportAdapter_1 = require("./AgGridExportAdapter");
19
19
  const AdaptableHelper_1 = require("../Utilities/Helpers/AdaptableHelper");
20
+ const adaptableOverrideCheck_1 = require("../Utilities/adaptableOverrideCheck");
20
21
  function getEditorForColumnDataType(columnDataType, variant) {
21
22
  if (columnDataType === 'number') {
22
23
  return variant === 'react' ? AdaptableNumberEditor_1.AdaptableReactNumberEditor : AdaptableNumberEditor_1.AdaptableNumberEditor;
@@ -376,19 +377,12 @@ class AgGridColumnAdapter {
376
377
  });
377
378
  }
378
379
  setupColumnHeader({ col, abColumn }) {
379
- const previousColumnHeader = col?.getColDef()?.headerName;
380
- this.setColDefProperty(col, 'headerName', (userHeaderName) => {
381
- // set the default to the AG Grid provided values
382
- // from https://github.com/ag-grid/ag-grid/blob/v26.1.0/community-modules/core/src/ts/columns/columnModel.ts#L2515
383
- let resultHeaderName = userHeaderName ?? StringExtensions_1.default.CamelCaseToHumanText(col.getColDef().field);
384
- const layoutCustomHeader = this.adaptableApi.layoutApi.getCurrentLayout().ColumnHeaders?.[col.getColId()];
385
- if (layoutCustomHeader) {
386
- resultHeaderName = layoutCustomHeader;
387
- }
388
- return resultHeaderName;
380
+ this.setColDefProperty(col, 'headerValueGetter', (original_headerValueGetter) => {
381
+ if (!(0, adaptableOverrideCheck_1.isProvidedByAdaptable)(original_headerValueGetter)) {
382
+ this.adaptableApi.logWarn(`colDef.headerValueGetter is defined for column '${col.getColId()}', and overrides the Adaptable custom header mechanism! We recommend using a ColumnOptions.tableColumnHeader instead!`);
383
+ }
384
+ return original_headerValueGetter;
389
385
  });
390
- const newColumnHeader = col?.getColDef()?.headerName;
391
- return previousColumnHeader !== newColumnHeader;
392
386
  }
393
387
  setupColumnFilter({ col, colDef }) {
394
388
  this.setColDefProperty(col, 'filter', () => {
package/src/env.js CHANGED
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  NEXT_PUBLIC_INFINITE_TABLE_LICENSE_KEY: "StartDate=2021-06-29|EndDate=2030-01-01|Owner=Adaptable|Type=distribution|TS=1624971462479|C=137829811,1004007071,2756196225,1839832928,3994409405,636616862" || '',
5
- PUBLISH_TIMESTAMP: 1744973638081 || Date.now(),
6
- VERSION: "20.0.6" || '--current-version--',
5
+ PUBLISH_TIMESTAMP: 1745430388589 || Date.now(),
6
+ VERSION: "20.0.7-canary.1" || '--current-version--',
7
7
  };
@@ -62,26 +62,17 @@ export type ColumnAggregationModel = {
62
62
  aggFunc: string | true;
63
63
  weightedColumnId?: string;
64
64
  };
65
- export type AggregationColumnsModel = {
65
+ export type AggregationColumnsModelItem = {
66
66
  ColumnId: string;
67
67
  AggFunc: ColumnAggregationModel;
68
- }[];
69
- type RowSummaryPosition = 'Top' | 'Bottom';
70
- export interface RowSummaryModel {
71
- /**
72
- * Where Row Summary appears - 'Top' or 'Bottom'
73
- */
74
- Position?: RowSummaryPosition;
75
- /**
76
- * Map of Columns with Summary Expressions
77
- */
78
- ColumnsMap: Record<string, string>;
79
- /**
80
- * Evaluates only currently filtered rows in the summary
81
- * @defaultValue true
82
- */
83
- IncludeOnlyFilteredRows?: boolean;
84
- }
68
+ };
69
+ export type AggregationColumnsModel = AggregationColumnsModelItem[];
70
+ export type PivotAggregationColumnsModel = (AggregationColumnsModelItem & {
71
+ TotalColumn?: boolean | 'before' | 'after' | {
72
+ PivotColumnId: string;
73
+ ShowTotal?: boolean | 'before' | 'after';
74
+ }[];
75
+ })[];
85
76
  export interface TableLayoutModel extends BaseLayoutModel {
86
77
  TableColumns: string[];
87
78
  /**
@@ -96,6 +87,7 @@ export interface TableLayoutModel extends BaseLayoutModel {
96
87
  * @defaultValue 'single'
97
88
  */
98
89
  RowGroupDisplayType?: 'single' | 'multi';
90
+ PivotAggregationColumns?: never;
99
91
  PivotColumns?: never;
100
92
  PivotGroupedColumns?: never;
101
93
  PivotExpandLevel?: never;
@@ -110,13 +102,24 @@ export interface PivotLayoutModel extends BaseLayoutModel {
110
102
  /**
111
103
  * Columns showing aggregated values in Group Rows; 1st value in record is Column name, 2nd is either aggfunc (e.g. sum, avg etc.) or 'true' (to use default aggfunc)
112
104
  */
113
- PivotAggregationColumns?: AggregationColumnsModel;
105
+ PivotAggregationColumns?: PivotAggregationColumnsModel;
114
106
  TableAggregationColumns?: never;
115
107
  /**
116
108
  * Columns which are row-grouped when the Layout is applied
117
109
  */
118
110
  PivotGroupedColumns?: string[];
119
111
  RowGroupedColumns?: never;
112
+ /**
113
+ * Display Grand Total Row at the top or bottom of the Pivot Table
114
+ */
115
+ GrandTotalRow?: 'top' | 'bottom' | boolean;
116
+ /**
117
+ * Display Total of all Pivot Columns before or after the Pivot Columns
118
+ */
119
+ GrandTotalColumn?: 'before' | 'after' | boolean;
120
+ /**
121
+ * Display automatically calculated Totals within EACH Pivot Column Group, in the position specified
122
+ */
123
+ PivotGroupTotalColumn?: 'before' | 'after' | boolean;
120
124
  }
121
125
  export type LayoutModel = TableLayoutModel | PivotLayoutModel;
122
- export {};
@@ -0,0 +1,10 @@
1
+ import { ColDef } from 'ag-grid-enterprise';
2
+ export declare function destructurePivotColumnId(colDef: ColDef, currentModel: {
3
+ pivotColIds: string[];
4
+ aggColIds: string[];
5
+ }, logWarning: (message: string) => void): '!unknown!' | {
6
+ pivotColumnIds: string[];
7
+ pivotKeys: string[];
8
+ pivotColumnId: string;
9
+ aggregationColumnId?: string;
10
+ };
@@ -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
  };