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

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.
@@ -120,12 +120,8 @@ 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);
126
123
  this.setupEvents();
127
124
  this.indexColumns();
128
- this.setupPivotTotals();
129
125
  globalThis.layoutManager = this;
130
126
  }
131
127
  destroy() {
@@ -259,18 +255,6 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
259
255
  PivotAggregationColumns: layout.TableAggregationColumns,
260
256
  PivotExpandLevel: prevLayout?.PivotExpandLevel ?? -1,
261
257
  };
262
- const grandTotalRow = this.gridApi.getGridOption('grandTotalRow');
263
- if (grandTotalRow) {
264
- pivotLayout.GrandTotalRow = grandTotalRow;
265
- }
266
- const grandTotalColumn = this.gridApi.getGridOption('pivotRowTotals');
267
- if (grandTotalColumn) {
268
- pivotLayout.GrandTotalColumn = grandTotalColumn;
269
- }
270
- const pivotGroupTotalColumn = this.gridApi.getGridOption('pivotColumnGroupTotals');
271
- if (pivotGroupTotalColumn) {
272
- pivotLayout.PivotGroupTotalColumn = pivotGroupTotalColumn;
273
- }
274
258
  return (0, simplifyLayoutModel_1.simplifyPivotLayoutModel)(pivotLayout);
275
259
  }
276
260
  getTableLayoutModelFromGrid() {
@@ -291,7 +275,7 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
291
275
  let ColumnPinning = {};
292
276
  const gridState = this.gridApi.getState();
293
277
  const prevLayout = this.currentLayout;
294
- const prevAggColumns = prevLayout?.TableAggregationColumns ?? prevLayout?.PivotAggregationColumns;
278
+ const prevAggColumns = prevLayout?.TableAggregationColumns;
295
279
  const prevAggColumnsMap = prevAggColumns?.reduce((acc, agg) => {
296
280
  acc[agg.ColumnId] = agg;
297
281
  return acc;
@@ -1002,7 +986,6 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1002
986
  return columnIds;
1003
987
  }
1004
988
  applyPivotLayout(layout, options) {
1005
- this.applyPivotTotals(layout);
1006
989
  const columnState = this.computeColumnStateForPivotLayout(layout);
1007
990
  // by simply calling this.gridApi.applyColumnState(columnState)
1008
991
  // the order of aggregations is not preserved/guaranteed by ag-grid
@@ -1030,50 +1013,6 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1030
1013
  this.applyRowGroupValues(layout.RowGroupValues);
1031
1014
  }
1032
1015
  }
1033
- applyPivotTotals(layout) {
1034
- /**
1035
- * GrandTotalRow
1036
- */
1037
- if (layout.GrandTotalRow) {
1038
- const grandTotalRow = layout.GrandTotalRow === true || layout.GrandTotalRow === 'top'
1039
- ? 'top'
1040
- : layout.GrandTotalRow === 'bottom'
1041
- ? 'bottom'
1042
- : null;
1043
- this.gridApi.setGridOption('grandTotalRow', grandTotalRow);
1044
- }
1045
- else {
1046
- this.gridApi.setGridOption('grandTotalRow', null);
1047
- }
1048
- /**
1049
- * GrandTotalColumn
1050
- */
1051
- if (layout.GrandTotalColumn) {
1052
- const grandTotalColumn = layout.GrandTotalColumn === true || layout.GrandTotalColumn === 'before'
1053
- ? 'before'
1054
- : layout.GrandTotalColumn === 'after'
1055
- ? 'after'
1056
- : null;
1057
- this.gridApi.setGridOption('pivotRowTotals', grandTotalColumn);
1058
- }
1059
- else {
1060
- this.gridApi.setGridOption('pivotRowTotals', null);
1061
- }
1062
- /**
1063
- * PivotGroupTotalColumn
1064
- */
1065
- if (layout.PivotGroupTotalColumn) {
1066
- const pivotGroupTotalColumn = layout.PivotGroupTotalColumn === true || layout.PivotGroupTotalColumn === 'before'
1067
- ? 'before'
1068
- : layout.PivotGroupTotalColumn === 'after'
1069
- ? 'after'
1070
- : null;
1071
- this.gridApi.setGridOption('pivotColumnGroupTotals', pivotGroupTotalColumn);
1072
- }
1073
- else {
1074
- this.gridApi.setGridOption('pivotColumnGroupTotals', null);
1075
- }
1076
- }
1077
1016
  applyPivotExpandLevel(layout) {
1078
1017
  const PivotExpandLevel = layout.PivotExpandLevel ?? -1;
1079
1018
  const allDisplayedColumnGroups = this.gridApi.getAllDisplayedColumnGroups();
@@ -1109,230 +1048,5 @@ class LayoutManager extends LMEmitter_1.LMEmitter {
1109
1048
  }
1110
1049
  return res;
1111
1050
  }
1112
- setupPivotTotals() {
1113
- const _original_processPivotResultColDef = this.gridApi.getGridOption('processPivotResultColDef');
1114
- this.gridApi.setGridOption('processPivotResultColDef', (resulColDef) => {
1115
- _original_processPivotResultColDef?.(resulColDef);
1116
- if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout)) {
1117
- return;
1118
- }
1119
- // column that contain the aggregated total for each value column per row
1120
- this.patchGrandTotalColumn(resulColDef);
1121
- this.patchPivotGroupTotalColumn(resulColDef);
1122
- });
1123
- const _original_processPivotResultColGroupDef = this.gridApi.getGridOption('processPivotResultColGroupDef');
1124
- this.gridApi.setGridOption('processPivotResultColGroupDef', (colGroupDef) => {
1125
- _original_processPivotResultColGroupDef?.(colGroupDef);
1126
- if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout)) {
1127
- return;
1128
- }
1129
- this.patchPivotTotalColumn(colGroupDef);
1130
- });
1131
- }
1132
- isPivotRowTotalColDef(colDef) {
1133
- return colDef.colId?.startsWith('PivotRowTotal_');
1134
- }
1135
- patchGrandTotalColumn(resultColDef) {
1136
- if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout) || !this.currentLayout.GrandTotalColumn) {
1137
- return;
1138
- }
1139
- if (this.isPivotRowTotalColDef(resultColDef)) {
1140
- resultColDef.headerName = `Grand Total ${resultColDef.headerName}`;
1141
- }
1142
- }
1143
- isPivotGroupTotalColumn(colDef) {
1144
- // pivot group total are spanning cross all aggregations
1145
- // therefore the last part of the colId is empty (hence the "dangling" underscore)
1146
- return colDef.colId?.startsWith('pivot_') && colDef.colId?.endsWith('_');
1147
- }
1148
- patchPivotGroupTotalColumn(resultColDef) {
1149
- if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout) || !this.currentLayout.PivotGroupTotalColumn) {
1150
- return;
1151
- }
1152
- if (this.isPivotGroupTotalColumn(resultColDef)) {
1153
- // resultColDef
1154
- const colInfo = this.destructurePivotColumnId(resultColDef, {
1155
- pivotColIds: this.currentLayout.PivotColumns,
1156
- aggColIds: this.currentLayout.PivotAggregationColumns.map((col) => col.ColumnId),
1157
- });
1158
- if (colInfo !== '!unknown!') {
1159
- const currentPivotKey = colInfo.pivotKeys[colInfo.pivotKeys.length - 1];
1160
- resultColDef.headerName = `${currentPivotKey} Total`;
1161
- }
1162
- }
1163
- }
1164
- patchPivotTotalColumn(colGroupDef) {
1165
- const hasPivotTotalCols = (pivotLayout) => {
1166
- return pivotLayout.PivotAggregationColumns?.some((aggCol) => !!aggCol.TotalColumn);
1167
- };
1168
- const isPivotTotalColDef = (colDef) => {
1169
- return !!colDef.pivotTotalColumnIds?.length;
1170
- };
1171
- if (!(0, isPivotLayoutModel_1.isPivotLayoutModel)(this.currentLayout) || !hasPivotTotalCols(this.currentLayout)) {
1172
- return;
1173
- }
1174
- const pivotRowTotalColDefsBefore = [];
1175
- const pivotRowTotalColDefsAfter = [];
1176
- const pivotTotalColDefsBefore = [];
1177
- const pivotTotalColDefsAfter = [];
1178
- const normalColDefs = [];
1179
- colGroupDef.children.forEach((colDef) => {
1180
- if (this.isPivotRowTotalColDef(colDef)) {
1181
- if (this.gridApi.getGridOption('pivotRowTotals') === 'after') {
1182
- pivotRowTotalColDefsAfter.push(colDef);
1183
- }
1184
- else {
1185
- pivotRowTotalColDefsBefore.push(colDef);
1186
- }
1187
- return;
1188
- }
1189
- if (isPivotTotalColDef(colDef)) {
1190
- if (!colDef.colId.startsWith('pivot_')) {
1191
- this.warn(`Pivot total column ${colDef.colId} is not prefixed with 'pivot_', skipping...`);
1192
- return;
1193
- }
1194
- // we do this for all total cols, but we will hide the ones that are not visible
1195
- colDef.columnGroupShow = undefined;
1196
- colDef.headerName = `Total ${colDef.headerName}`;
1197
- const totalColConfig = this.getPivotTotalColumnConfig(colDef, this.currentLayout);
1198
- if (!totalColConfig.visible) {
1199
- colDef.hide = true;
1200
- }
1201
- else {
1202
- if (totalColConfig.position === 'after') {
1203
- pivotTotalColDefsAfter.push(colDef);
1204
- }
1205
- else {
1206
- pivotTotalColDefsBefore.push(colDef);
1207
- }
1208
- }
1209
- }
1210
- else {
1211
- normalColDefs.push(colDef);
1212
- }
1213
- });
1214
- colGroupDef.children = [
1215
- ...pivotRowTotalColDefsBefore,
1216
- ...pivotTotalColDefsBefore,
1217
- ...normalColDefs,
1218
- ...pivotTotalColDefsAfter,
1219
- ...pivotRowTotalColDefsAfter,
1220
- ];
1221
- }
1222
- // supports only pivotTotalColumns (aggregation total) and pivotGroupTotal
1223
- // AG Grid builds the ID as: `pivot_${pivotCols.join('-')}_${pivotKeys.join('-')}_${measureColumnId}`
1224
- // see https://github.com/ag-grid/ag-grid/blob/e0cfe533b55b75cdc148cdfb1a4e977731dc0712/packages/ag-grid-enterprise/src/pivot/pivotColDefService.ts#L454C16-L454C88
1225
- destructurePivotColumnId(colDef, currentModel) {
1226
- const { colId } = colDef;
1227
- // Basic validation
1228
- if (!colId?.startsWith('pivot_')) {
1229
- this.warn(`Column id must start with 'pivot_': ${colId}`);
1230
- return '!unknown!';
1231
- }
1232
- const hasSpecialChars = (arr) => arr.some((str) => str.includes('-') || str.includes('_'));
1233
- // AG Grid uses _ and - as delimiters
1234
- // if we have these special characters in the column IDs, we need to parse them differently
1235
- const colIdsOrKeysContainSpecialChars = hasSpecialChars(currentModel.pivotColIds) ||
1236
- hasSpecialChars(currentModel.aggColIds) ||
1237
- hasSpecialChars(colDef.pivotKeys || []);
1238
- // Fast path - no special characters
1239
- if (!colIdsOrKeysContainSpecialChars) {
1240
- // Split by underscore to get 4 parts
1241
- const parts = colId.split('_');
1242
- if (parts.length !== 4) {
1243
- this.warn(`Unsupported format of pivot total column id: ${colId}`);
1244
- return '!unknown!';
1245
- }
1246
- const [_pivotPrefix, pivotColsTxt, pivotKeysTxt, aggregationColumnId] = parts;
1247
- const pivotColumnIds = pivotColsTxt.split('-');
1248
- const pivotKeys = pivotKeysTxt.split('-');
1249
- const pivotColumnId = pivotColumnIds[pivotKeys.length - 1];
1250
- return {
1251
- pivotColumnIds,
1252
- pivotKeys,
1253
- pivotColumnId,
1254
- aggregationColumnId: aggregationColumnId !== '' ? aggregationColumnId : undefined,
1255
- };
1256
- }
1257
- // the complex path, where we have to handle the special characters
1258
- // Remove 'pivot_' prefix
1259
- const withoutPrefix = colId.slice(6);
1260
- // Check if it's a pivot group total
1261
- const isPivotGroupTotal = withoutPrefix.endsWith('_');
1262
- // Get pivot keys from colDef (more reliable than string parsing)
1263
- const pivotKeys = colDef.pivotKeys || [];
1264
- if (isPivotGroupTotal) {
1265
- // Remove trailing underscore for pivot group totals
1266
- const content = withoutPrefix.slice(0, -1);
1267
- // The remaining content should be the pivot columns
1268
- const pivotColumnIds = currentModel.pivotColIds.filter((id) => content.includes(id));
1269
- if (!pivotColumnIds.length) {
1270
- this.warn(`Could not identify pivot columns in: ${content}`);
1271
- return '!unknown!';
1272
- }
1273
- return {
1274
- pivotColumnIds,
1275
- pivotKeys,
1276
- pivotColumnId: pivotColumnIds[pivotKeys.length],
1277
- };
1278
- }
1279
- // For regular pivot columns, work backwards to find aggregation column
1280
- const parts = withoutPrefix.split('_');
1281
- const lastPart = parts[parts.length - 1];
1282
- // Find the longest matching aggregation column id from the end
1283
- const aggregationColumnId = currentModel.aggColIds.find((aggId) => lastPart.endsWith(aggId));
1284
- if (!aggregationColumnId) {
1285
- this.warn(`Could not identify aggregation column in: ${lastPart}`);
1286
- return '!unknown!';
1287
- }
1288
- // Remove aggregation part and get pivot columns
1289
- const withoutAgg = withoutPrefix.slice(0, -(aggregationColumnId.length + 1));
1290
- const pivotColumnIds = currentModel.pivotColIds.filter((id) => withoutAgg.includes(id));
1291
- if (!pivotColumnIds.length) {
1292
- this.warn(`Could not identify pivot columns in: ${withoutAgg}`);
1293
- return '!unknown!';
1294
- }
1295
- return {
1296
- pivotColumnIds,
1297
- pivotKeys,
1298
- pivotColumnId: pivotColumnIds[pivotKeys.length - 1],
1299
- aggregationColumnId,
1300
- };
1301
- }
1302
- getPivotTotalColumnConfig(colDef, currentPivotLayout) {
1303
- const defaultHiddenConfig = {
1304
- visible: false,
1305
- };
1306
- const colIdInfo = this.destructurePivotColumnId(colDef, {
1307
- pivotColIds: this.currentLayout.PivotColumns,
1308
- aggColIds: this.currentLayout.PivotAggregationColumns.map((col) => col.ColumnId),
1309
- });
1310
- if (colIdInfo === '!unknown!') {
1311
- return defaultHiddenConfig;
1312
- }
1313
- const { pivotColumnId, aggregationColumnId } = colIdInfo;
1314
- const layoutAggCol = currentPivotLayout.PivotAggregationColumns?.find((col) => col.ColumnId === aggregationColumnId);
1315
- if (!layoutAggCol) {
1316
- this.warn(`Pivot Totals: could NOT find aggregation(value) column with id ${aggregationColumnId}`);
1317
- return defaultHiddenConfig;
1318
- }
1319
- const layoutPivotTotalColumn = layoutAggCol.TotalColumn;
1320
- if (!layoutPivotTotalColumn) {
1321
- return defaultHiddenConfig;
1322
- }
1323
- if (Array.isArray(layoutPivotTotalColumn)) {
1324
- const pivotSpecificConfig = layoutPivotTotalColumn.find((config) => config.PivotColumnId === pivotColumnId);
1325
- return {
1326
- visible: pivotSpecificConfig && pivotSpecificConfig.ShowTotal !== false,
1327
- position: pivotSpecificConfig?.ShowTotal === 'after' ? 'after' : 'before',
1328
- };
1329
- }
1330
- else {
1331
- return {
1332
- visible: !!layoutPivotTotalColumn,
1333
- position: layoutPivotTotalColumn === 'after' ? 'after' : 'before',
1334
- };
1335
- }
1336
- }
1337
1051
  }
1338
1052
  exports.LayoutManager = LayoutManager;
@@ -144,9 +144,6 @@ 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
- }
150
147
  return layout;
151
148
  }
152
149
  exports.normalizePivotLayoutModel = normalizePivotLayoutModel;