@adaptabletools/adaptable-cjs 20.0.3-canary.0 → 20.0.4-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptabletools/adaptable-cjs",
3
- "version": "20.0.3-canary.0",
3
+ "version": "20.0.4-canary.0",
4
4
  "description": "Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements",
5
5
  "keywords": [
6
6
  "web-components",
@@ -12,7 +12,14 @@ export type TableAggregationColumns = {
12
12
  /**
13
13
  * Defines an Aggregated Column in a Pivot Layout
14
14
  */
15
- export type PivotAggregationColumns = TableAggregationColumns;
15
+ export type PivotAggregationColumns = {
16
+ ColumnId: string;
17
+ AggFunc: AggregationColumnValue;
18
+ TotalColumn?: boolean | 'before' | 'after' | {
19
+ PivotColumnId: string;
20
+ ShowTotal?: boolean | 'before' | 'after';
21
+ }[];
22
+ }[];
16
23
  export declare const WEIGHTED_AVERAGE_AGG_FN_NAME = "weightedAvg";
17
24
  /**
18
25
  * Defines a Weighted Average Agg
@@ -16,7 +16,7 @@ export interface BaseContext {
16
16
  */
17
17
  adaptableId: string;
18
18
  /**
19
- * Custom applicaton Context provided in Adaptable Options
19
+ * Custom application Context provided in `AdaptableOptions.adaptableContext`
20
20
  */
21
21
  adaptableContext: any;
22
22
  /**
@@ -148,6 +148,18 @@ export interface PivotLayout extends LayoutBase {
148
148
  * Row Grouped Columns Columns - must NOT be provided
149
149
  */
150
150
  RowGroupedColumns?: never;
151
+ /**
152
+ * Display Grand Total Row at the top or bottom of the Pivot Table
153
+ */
154
+ GrandTotalRow?: 'top' | 'bottom' | boolean;
155
+ /**
156
+ * Display automatically calculated Totals of all Pivot Columns, in the position specified
157
+ */
158
+ GrandTotalColumn?: 'before' | 'after' | boolean;
159
+ /**
160
+ * Display automatically calculated Totals within EACH Pivot Column Group, in the position specified
161
+ */
162
+ PivotGroupTotalColumn?: 'before' | 'after' | boolean;
151
163
  }
152
164
  /**
153
165
  * Manages how (and which) Row Group values are stored
@@ -209,12 +209,16 @@ const pivotLayoutToPivotLayoutModel = (pivotLayout) => {
209
209
  ColumnPinning: pivotLayout.ColumnPinning,
210
210
  PivotColumns: pivotLayout.PivotColumns,
211
211
  PivotExpandLevel: pivotLayout.PivotExpandLevel,
212
- PivotAggregationColumns: (pivotLayout.PivotAggregationColumns || []).map(({ ColumnId, AggFunc }) => {
212
+ PivotAggregationColumns: (pivotLayout.PivotAggregationColumns || []).map(({ ColumnId, AggFunc, TotalColumn }) => {
213
213
  return {
214
214
  ColumnId,
215
215
  AggFunc: toAggFunc(AggFunc),
216
+ TotalColumn,
216
217
  };
217
218
  }),
219
+ GrandTotalRow: pivotLayout.GrandTotalRow,
220
+ GrandTotalColumn: pivotLayout.GrandTotalColumn,
221
+ PivotGroupTotalColumn: pivotLayout.PivotGroupTotalColumn,
218
222
  RowGroupValues: pivotLayout.RowGroupValues
219
223
  ? pivotLayout.RowGroupValues.RowGroupDefaultBehavior === 'always-collapsed' ||
220
224
  pivotLayout.RowGroupValues.RowGroupDefaultBehavior === 'always-expanded'
@@ -340,10 +344,20 @@ const pivotLayoutModelToPivotLayout = (layoutModel, defaults) => {
340
344
  else {
341
345
  delete pivotLayout.RowGroupValues;
342
346
  }
347
+ if (layoutModel.GrandTotalRow) {
348
+ pivotLayout.GrandTotalRow = layoutModel.GrandTotalRow;
349
+ }
350
+ if (layoutModel.GrandTotalColumn) {
351
+ pivotLayout.GrandTotalColumn = layoutModel.GrandTotalColumn;
352
+ }
353
+ if (layoutModel.PivotGroupTotalColumn) {
354
+ pivotLayout.PivotGroupTotalColumn = layoutModel.PivotGroupTotalColumn;
355
+ }
343
356
  if (layoutModel.PivotAggregationColumns) {
344
- pivotLayout.PivotAggregationColumns = (layoutModel.PivotAggregationColumns || []).map(({ ColumnId, AggFunc }) => ({
357
+ pivotLayout.PivotAggregationColumns = (layoutModel.PivotAggregationColumns || []).map(({ ColumnId, AggFunc, TotalColumn }) => ({
345
358
  ColumnId,
346
359
  AggFunc: toAggregationColumnValue(AggFunc),
360
+ TotalColumn,
347
361
  }));
348
362
  }
349
363
  else {
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: 1743753806257 || Date.now(),
6
- VERSION: "20.0.3-canary.0" || '--current-version--',
5
+ PUBLISH_TIMESTAMP: 1744377466461 || Date.now(),
6
+ VERSION: "20.0.4-canary.0" || '--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 {};
@@ -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 patchGrandTotalColumn;
77
+ private patchPivotTotalColumn;
78
+ private getPivotTotalColumnConfig;
74
79
  }
75
80
  export {};
@@ -120,8 +120,12 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
120
120
  }).bind(this);
121
121
  }
122
122
  this.setOptions(options);
123
+ // this ensures the grand total columns are positioned correctly (before/after) even when changed at runtime
124
+ // see https://www.ag-grid.com/react-data-grid/pivoting-column-groups/#changing-data-filters-and-configurations
125
+ this.gridApi.setGridOption('enableStrictPivotColumnOrder', true);
123
126
  this.setupEvents();
124
127
  this.indexColumns();
128
+ this.setupPivotTotals();
125
129
  globalThis.layoutManager = this;
126
130
  }
127
131
  destroy() {
@@ -275,7 +279,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
275
279
  let ColumnPinning = {};
276
280
  const gridState = this.gridApi.getState();
277
281
  const prevLayout = this.currentLayout;
278
- const prevAggColumns = prevLayout?.TableAggregationColumns;
282
+ const prevAggColumns = prevLayout?.TableAggregationColumns ?? prevLayout?.PivotAggregationColumns;
279
283
  const prevAggColumnsMap = prevAggColumns?.reduce((acc, agg) => {
280
284
  acc[agg.ColumnId] = agg;
281
285
  return acc;
@@ -986,6 +990,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
986
990
  return columnIds;
987
991
  }
988
992
  applyPivotLayout(layout, options) {
993
+ this.applyPivotTotals(layout);
989
994
  const columnState = this.computeColumnStateForPivotLayout(layout);
990
995
  // by simply calling this.gridApi.applyColumnState(columnState)
991
996
  // the order of aggregations is not preserved/guaranteed by ag-grid
@@ -1013,6 +1018,50 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1013
1018
  this.applyRowGroupValues(layout.RowGroupValues);
1014
1019
  }
1015
1020
  }
1021
+ applyPivotTotals(layout) {
1022
+ /**
1023
+ * GrandTotalRow
1024
+ */
1025
+ if (layout.GrandTotalRow) {
1026
+ const grandTotalRow = layout.GrandTotalRow === true || layout.GrandTotalRow === 'top'
1027
+ ? 'top'
1028
+ : layout.GrandTotalRow === 'bottom'
1029
+ ? 'bottom'
1030
+ : null;
1031
+ this.gridApi.setGridOption('grandTotalRow', grandTotalRow);
1032
+ }
1033
+ else {
1034
+ this.gridApi.setGridOption('grandTotalRow', null);
1035
+ }
1036
+ /**
1037
+ * GrandTotalColumn
1038
+ */
1039
+ if (layout.GrandTotalColumn) {
1040
+ const grandTotalColumn = layout.GrandTotalColumn === true || layout.GrandTotalColumn === 'before'
1041
+ ? 'before'
1042
+ : layout.GrandTotalColumn === 'after'
1043
+ ? 'after'
1044
+ : null;
1045
+ this.gridApi.setGridOption('pivotRowTotals', grandTotalColumn);
1046
+ }
1047
+ else {
1048
+ this.gridApi.setGridOption('pivotRowTotals', null);
1049
+ }
1050
+ /**
1051
+ * PivotGroupTotalColumn
1052
+ */
1053
+ if (layout.PivotGroupTotalColumn) {
1054
+ const pivotGroupTotalColumn = layout.PivotGroupTotalColumn === true || layout.PivotGroupTotalColumn === 'before'
1055
+ ? 'before'
1056
+ : layout.PivotGroupTotalColumn === 'after'
1057
+ ? 'after'
1058
+ : null;
1059
+ this.gridApi.setGridOption('pivotColumnGroupTotals', pivotGroupTotalColumn);
1060
+ }
1061
+ else {
1062
+ this.gridApi.setGridOption('pivotColumnGroupTotals', null);
1063
+ }
1064
+ }
1016
1065
  applyPivotExpandLevel(layout) {
1017
1066
  const PivotExpandLevel = layout.PivotExpandLevel ?? -1;
1018
1067
  const allDisplayedColumnGroups = this.gridApi.getAllDisplayedColumnGroups();
@@ -1048,5 +1097,119 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1048
1097
  }
1049
1098
  return res;
1050
1099
  }
1100
+ setupPivotTotals() {
1101
+ const _original_processPivotResultColDef = this.gridApi.getGridOption('processPivotResultColDef');
1102
+ this.gridApi.setGridOption('processPivotResultColDef', (resulColDef) => {
1103
+ _original_processPivotResultColDef?.(resulColDef);
1104
+ if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout)) {
1105
+ return;
1106
+ }
1107
+ this.patchGrandTotalColumn(resulColDef);
1108
+ });
1109
+ const _original_processPivotResultColGroupDef = this.gridApi.getGridOption('processPivotResultColGroupDef');
1110
+ this.gridApi.setGridOption('processPivotResultColGroupDef', (colGroupDef) => {
1111
+ _original_processPivotResultColGroupDef?.(colGroupDef);
1112
+ if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout)) {
1113
+ return;
1114
+ }
1115
+ this.patchPivotTotalColumn(colGroupDef);
1116
+ });
1117
+ }
1118
+ patchGrandTotalColumn(resultColDef) {
1119
+ if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout) || !this.currentLayout.GrandTotalColumn) {
1120
+ return;
1121
+ }
1122
+ if (resultColDef.colId?.startsWith('PivotRowTotal_')) {
1123
+ resultColDef.headerName = `Grand Total ${resultColDef.headerName}`;
1124
+ }
1125
+ }
1126
+ patchPivotTotalColumn(colGroupDef) {
1127
+ const hasPivotTotalCols = (pivotLayout) => {
1128
+ return pivotLayout.PivotAggregationColumns?.some((aggCol) => !!aggCol.TotalColumn);
1129
+ };
1130
+ const isPivotTotalColDef = (colDef) => {
1131
+ return !!colDef.pivotTotalColumnIds?.length;
1132
+ };
1133
+ if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout) || !hasPivotTotalCols(this.currentLayout)) {
1134
+ return;
1135
+ }
1136
+ const pivotTotalColDefsBefore = [];
1137
+ const pivotTotalColDefsAfter = [];
1138
+ const normalColDefs = [];
1139
+ colGroupDef.children.forEach((colDef) => {
1140
+ if (isPivotTotalColDef(colDef)) {
1141
+ if (!colDef.colId.startsWith('pivot_')) {
1142
+ this.warn(`Pivot total column ${colDef.colId} is not prefixed with 'pivot_', skipping...`);
1143
+ return;
1144
+ }
1145
+ // we do this for all total cols, but we will hide the ones that are not visible
1146
+ colDef.columnGroupShow = undefined;
1147
+ colDef.headerName = `Total ${colDef.headerName}`;
1148
+ const totalColConfig = this.getPivotTotalColumnConfig(colDef, this.currentLayout);
1149
+ if (!totalColConfig.visible) {
1150
+ colDef.hide = true;
1151
+ }
1152
+ else {
1153
+ if (totalColConfig.position === 'after') {
1154
+ pivotTotalColDefsAfter.push(colDef);
1155
+ }
1156
+ else {
1157
+ pivotTotalColDefsBefore.push(colDef);
1158
+ }
1159
+ }
1160
+ }
1161
+ else {
1162
+ normalColDefs.push(colDef);
1163
+ }
1164
+ });
1165
+ colGroupDef.children = [
1166
+ ...pivotTotalColDefsBefore,
1167
+ ...normalColDefs,
1168
+ ...pivotTotalColDefsAfter,
1169
+ ];
1170
+ }
1171
+ getPivotTotalColumnConfig(colDef, currentPivotLayout) {
1172
+ const defaultHiddenConfig = {
1173
+ visible: false,
1174
+ };
1175
+ const colId = colDef.colId;
1176
+ // Split by underscore to get 4 parts
1177
+ const parts = colId.split('_');
1178
+ if (parts.length !== 4) {
1179
+ this.warn(`Unsupported format of pivot total column id: ${colId}`);
1180
+ return defaultHiddenConfig;
1181
+ }
1182
+ // e.g.
1183
+ // pivot_country-sport-year_United States-Basketball_gold
1184
+ // pivotColumnIds: ['country', 'sport', 'year']
1185
+ // pivotKeys: ['United States', 'Basketball']
1186
+ // aggregationColumnId: 'gold'
1187
+ const [_pivotPrefix, pivotColsTxt, pivotKeysTxt, aggregationColumnId] = parts;
1188
+ const pivotColumnIds = pivotColsTxt.split('-');
1189
+ const pivotKeys = pivotKeysTxt.split('-');
1190
+ const layoutAggCol = currentPivotLayout.PivotAggregationColumns?.find((col) => col.ColumnId === aggregationColumnId);
1191
+ if (!layoutAggCol) {
1192
+ this.warn(`Pivot Totals: could NOT find aggregation(value) column with id ${aggregationColumnId}`);
1193
+ return defaultHiddenConfig;
1194
+ }
1195
+ const layoutPivotTotalColumn = layoutAggCol.TotalColumn;
1196
+ if (!layoutPivotTotalColumn) {
1197
+ return defaultHiddenConfig;
1198
+ }
1199
+ const pivotColumnId = pivotColumnIds[pivotKeys.length - 1];
1200
+ if (Array.isArray(layoutPivotTotalColumn)) {
1201
+ const pivotSpecificConfig = layoutPivotTotalColumn.find((config) => config.PivotColumnId === pivotColumnId);
1202
+ return {
1203
+ visible: pivotSpecificConfig && pivotSpecificConfig.ShowTotal !== false,
1204
+ position: pivotSpecificConfig?.ShowTotal === 'after' ? 'after' : 'before',
1205
+ };
1206
+ }
1207
+ else {
1208
+ return {
1209
+ visible: !!layoutPivotTotalColumn,
1210
+ position: layoutPivotTotalColumn === 'after' ? 'after' : 'before',
1211
+ };
1212
+ }
1213
+ }
1051
1214
  }
1052
1215
  exports.LayoutManager = LayoutManager;
@@ -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;