@adaptabletools/adaptable 24.0.3 → 24.0.4

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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/AdaptableInterfaces/IAdaptable.d.ts +7 -0
  3. package/src/Api/AdaptableApi.d.ts +12 -0
  4. package/src/Api/GridApi.d.ts +13 -3
  5. package/src/Api/Implementation/AdaptableApiImpl.d.ts +1 -0
  6. package/src/Api/Implementation/AdaptableApiImpl.js +3 -0
  7. package/src/Api/Implementation/FlashingCellApiImpl.js +3 -8
  8. package/src/Api/Implementation/GridApiImpl.js +1 -1
  9. package/src/Api/Internal/AlertInternalApi.d.ts +7 -0
  10. package/src/Api/Internal/AlertInternalApi.js +42 -9
  11. package/src/Strategy/FlashingCellModule.js +2 -1
  12. package/src/Utilities/Helpers/CellValueHelper.d.ts +20 -0
  13. package/src/Utilities/Helpers/CellValueHelper.js +35 -0
  14. package/src/Utilities/Services/CalculatedColumnExpressionService.d.ts +25 -1
  15. package/src/Utilities/Services/CalculatedColumnExpressionService.js +160 -42
  16. package/src/Utilities/Services/DataService.js +10 -6
  17. package/src/Utilities/Services/FlashingCellService.d.ts +12 -0
  18. package/src/Utilities/Services/FlashingCellService.js +40 -3
  19. package/src/Utilities/Services/Interface/ICalculatedColumnExpressionService.d.ts +5 -0
  20. package/src/Utilities/Services/Interface/IQueryLanguageService.d.ts +5 -0
  21. package/src/Utilities/Services/QueryLanguageService.d.ts +6 -0
  22. package/src/Utilities/Services/QueryLanguageService.js +29 -1
  23. package/src/agGrid/AdaptableAgGrid.d.ts +80 -14
  24. package/src/agGrid/AdaptableAgGrid.js +468 -125
  25. package/src/agGrid/AgGridAdapter.d.ts +10 -1
  26. package/src/agGrid/AgGridAdapter.js +16 -0
  27. package/src/env.js +2 -2
  28. package/tsconfig.esm.tsbuildinfo +1 -1
@@ -27,6 +27,7 @@ import { ValidationService } from '../Utilities/Services/ValidationService';
27
27
  import { ModuleService } from '../Utilities/Services/ModuleService';
28
28
  import { CalculatedColumnExpressionService } from '../Utilities/Services/CalculatedColumnExpressionService';
29
29
  import { expandCellDataChangedInfosWithCalculatedColumns } from '../Utilities/Services/CalculatedColumnExpressionService';
30
+ import { areCellValuesEqual, getDataBackedColumns, } from '../Utilities/Helpers/CellValueHelper';
30
31
  import { QueryLanguageService } from '../Utilities/Services/QueryLanguageService';
31
32
  import { LiveRefreshService } from '../Utilities/Services/LiveRefreshService';
32
33
  import { AlertLiveBindingService } from '../Utilities/Services/AlertLiveBindingService';
@@ -130,6 +131,9 @@ import { AdaptableFilterHandler } from './AdaptableFilterHandler';
130
131
  import { getColumnFilterInListValues } from '../aql/columnFilterQl';
131
132
  import { AgGridFloatingFilterAdapterFactory } from './AgGridFloatingFilterAdapter';
132
133
  import { listenForDevTools } from '../setupDevTools';
134
+ const getChangedCellKey = (primaryKeyValue, columnId) => `${primaryKeyValue}\u0000${columnId}`;
135
+ const getPinnedCopySource = (rowNode) => rowNode?.rowPinned != null ? rowNode.pinnedSibling : undefined;
136
+ const hasLocalEventService = (rowNode) => !!rowNode.__localEventService;
133
137
  export class AdaptableAgGrid {
134
138
  logger;
135
139
  lifecycleState;
@@ -170,7 +174,21 @@ export class AdaptableAgGrid {
170
174
  LicenseService;
171
175
  ChartingService;
172
176
  isListeningToAgGridRowNodeEvents = false;
173
- offScreenRowUpdateTrackers = [];
177
+ trackedRowData = new Map();
178
+ pendingAsyncRowNodes = new Map();
179
+ pendingAsyncTransactions = 0;
180
+ syncTransactionDepth = 0;
181
+ refilterAfterAsyncFlush = false;
182
+ reportedCellChanges = new Map();
183
+ isReportedCellChangesClearScheduled = false;
184
+ updateCellCapture;
185
+ postEditBatch;
186
+ pendingPinnedCopyRefreshes = new Map();
187
+ dataBackedColumnsCache;
188
+ isRowIdPrimaryKey = false;
189
+ primaryKeyLookup;
190
+ hasLoggedPrimaryKeyLookupFallback = false;
191
+ hasWarnedSameObjectUpdate = false;
174
192
  debouncedSetSelectedRows;
175
193
  debouncedSetSelectedCells;
176
194
  agGridListenerKeydown;
@@ -893,6 +911,7 @@ export class AdaptableAgGrid {
893
911
  if (StringExtensions.IsNullOrEmpty(primaryKey)) {
894
912
  return original_getRowId;
895
913
  }
914
+ this.isRowIdPrimaryKey = true;
896
915
  if (this.hasAutogeneratedPrimaryKey) {
897
916
  return (params) => {
898
917
  if (Helper.objectNotExists(params.data[primaryKey])) {
@@ -1626,49 +1645,105 @@ export class AdaptableAgGrid {
1626
1645
  }
1627
1646
  if (event.type === 'dataChanged') {
1628
1647
  const { node, oldData, newData } = event;
1629
- this.noteRowNodeDataChanged(node?.id);
1630
- this.onRowDataChanged({ rowNode: node, oldData, newData });
1648
+ const sourceNode = getPinnedCopySource(node);
1649
+ if (sourceNode && hasLocalEventService(sourceNode)) {
1650
+ this.applyPendingPinnedCopyRefresh(node);
1651
+ return;
1652
+ }
1653
+ const rowNode = sourceNode ?? node;
1654
+ const isPendingAsyncRow = this.pendingAsyncRowNodes.has(rowNode);
1655
+ if (this.trackedRowData.has(rowNode)) {
1656
+ this.trackedRowData.set(rowNode, newData);
1657
+ }
1658
+ this.onRowDataChanged({
1659
+ rowNode,
1660
+ oldData,
1661
+ newData,
1662
+ deferRefilter: isPendingAsyncRow && !this.postEditBatch,
1663
+ });
1631
1664
  return;
1632
1665
  }
1633
1666
  if (event.type === 'cellChanged') {
1634
1667
  const { node, column, oldValue, newValue } = event;
1635
- if (column) {
1636
- this.onCellDataChanged({ rowNode: node, oldValue, newValue, colId: column.getColId() });
1668
+ if (!column) {
1669
+ return;
1670
+ }
1671
+ const sourceNode = getPinnedCopySource(node);
1672
+ if (sourceNode && hasLocalEventService(sourceNode)) {
1673
+ return;
1637
1674
  }
1675
+ const rowNode = sourceNode ?? node;
1676
+ const colId = column.getColId();
1677
+ this.noteCellChangeReported(rowNode, colId);
1678
+ const reportedByRowNode = this.updateCellCapture?.reportedByRowNode;
1679
+ if (reportedByRowNode) {
1680
+ let colIds = reportedByRowNode.get(rowNode);
1681
+ if (!colIds) {
1682
+ colIds = new Set();
1683
+ reportedByRowNode.set(rowNode, colIds);
1684
+ }
1685
+ colIds.add(colId);
1686
+ }
1687
+ this.onCellDataChanged({ rowNode, oldValue, newValue, colId });
1638
1688
  }
1639
1689
  }
1640
1690
  onAgGridCellValueChanged(event) {
1641
1691
  if (!this.isListeningToAgGridRowNodeEvents) {
1642
1692
  return;
1643
1693
  }
1644
- if (this.offScreenRowUpdateTrackers.length > 0) {
1645
- return;
1646
- }
1647
1694
  const node = event.node;
1648
1695
  const column = event.column;
1649
1696
  if (!node || !column) {
1650
1697
  return;
1651
1698
  }
1652
- if (node.__localEventService) {
1699
+ if (getPinnedCopySource(node)) {
1653
1700
  return;
1654
1701
  }
1655
- if (node.rowPinned != null && node.pinnedSibling) {
1702
+ const colId = column.getColId();
1703
+ if (this.takeCellChangeReported(node, colId)) {
1656
1704
  return;
1657
1705
  }
1658
1706
  this.onCellDataChanged({
1659
1707
  rowNode: node,
1660
1708
  oldValue: event.oldValue,
1661
1709
  newValue: event.newValue,
1662
- colId: column.getColId(),
1710
+ colId,
1663
1711
  });
1664
1712
  }
1665
- noteRowNodeDataChanged(rowId) {
1666
- if (rowId == null || this.offScreenRowUpdateTrackers.length === 0) {
1667
- return;
1713
+ onAgGridCellValueChangedDispatch(event) {
1714
+ this.updateCellCapture?.events.push(event);
1715
+ }
1716
+ noteCellChangeReported(rowNode, colId) {
1717
+ if (!this.isReportedCellChangesClearScheduled) {
1718
+ this.isReportedCellChangesClearScheduled = true;
1719
+ queueMicrotask(() => setTimeout(() => {
1720
+ this.isReportedCellChangesClearScheduled = false;
1721
+ this.reportedCellChanges.clear();
1722
+ }, 0));
1668
1723
  }
1669
- for (const tracker of this.offScreenRowUpdateTrackers) {
1670
- tracker.seenIds.add(rowId);
1724
+ let countByColId = this.reportedCellChanges.get(rowNode);
1725
+ if (!countByColId) {
1726
+ countByColId = new Map();
1727
+ this.reportedCellChanges.set(rowNode, countByColId);
1671
1728
  }
1729
+ countByColId.set(colId, (countByColId.get(colId) ?? 0) + 1);
1730
+ }
1731
+ takeCellChangeReported(rowNode, colId) {
1732
+ const countByColId = this.reportedCellChanges.get(rowNode);
1733
+ const count = countByColId?.get(colId);
1734
+ if (!count) {
1735
+ return false;
1736
+ }
1737
+ if (count > 1) {
1738
+ countByColId.set(colId, count - 1);
1739
+ }
1740
+ else {
1741
+ countByColId.delete(colId);
1742
+ if (countByColId.size === 0) {
1743
+ this.reportedCellChanges.delete(rowNode);
1744
+ }
1745
+ }
1746
+ return true;
1672
1747
  }
1673
1748
  shouldAutoSizeLayout() {
1674
1749
  const { layoutApi } = this.api;
@@ -2308,84 +2383,124 @@ export class AdaptableAgGrid {
2308
2383
  const agGridApi = this.agGridAdapter.getAgGridApi();
2309
2384
  this.countTransactionForPerf(transaction);
2310
2385
  if (isServerSideRowModel) {
2311
- return agGridApi.applyServerSideTransaction(transaction);
2312
- }
2313
- const tracking = this.beginOffScreenRowUpdateTracking(transaction.update);
2314
- try {
2315
- const result = agGridApi.applyTransaction(transaction);
2316
- this.emitOffScreenRowUpdates(tracking, result?.update);
2317
- return result;
2318
- }
2319
- finally {
2320
- this.endOffScreenRowUpdateTracking(tracking);
2386
+ return this.runPostEditBatch(() => {
2387
+ const result = agGridApi.applyServerSideTransaction(transaction);
2388
+ this.addToPrimaryKeyLookup(result?.add);
2389
+ return result;
2390
+ });
2321
2391
  }
2392
+ return this.runPostEditBatch(() => {
2393
+ this.trackRowUpdates(transaction.update);
2394
+ this.syncTransactionDepth++;
2395
+ try {
2396
+ const result = agGridApi.applyTransaction(transaction);
2397
+ this.postEditBatch.renderedRowIds = undefined;
2398
+ this.addToPrimaryKeyLookup(result?.add);
2399
+ this.reportTrackedRowUpdates(result?.update);
2400
+ return result;
2401
+ }
2402
+ finally {
2403
+ this.syncTransactionDepth--;
2404
+ this.releaseTrackedRows();
2405
+ }
2406
+ });
2322
2407
  }
2323
2408
  applyAgGridTransactionAsync(transaction, callback) {
2324
2409
  const isServerSideRowModel = this.getAgGridRowModelType() === 'serverSide';
2325
2410
  const agGridApi = this.agGridAdapter.getAgGridApi();
2326
2411
  this.countTransactionForPerf(transaction);
2327
2412
  if (isServerSideRowModel) {
2328
- return agGridApi.applyServerSideTransactionAsync(transaction, callback);
2413
+ return agGridApi.applyServerSideTransactionAsync(transaction, (result) => {
2414
+ this.addToPrimaryKeyLookup(result?.add);
2415
+ callback(result);
2416
+ });
2417
+ }
2418
+ const trackedNodes = this.trackRowUpdates(transaction.update);
2419
+ this.pendingAsyncTransactions++;
2420
+ for (const node of trackedNodes) {
2421
+ this.pendingAsyncRowNodes.set(node, (this.pendingAsyncRowNodes.get(node) ?? 0) + 1);
2329
2422
  }
2330
- const tracking = this.beginOffScreenRowUpdateTracking(transaction.update);
2331
2423
  const wrappedCallback = (result) => {
2332
2424
  try {
2333
- this.emitOffScreenRowUpdates(tracking, result?.update);
2425
+ this.runPostEditBatch(() => {
2426
+ if (this.refilterAfterAsyncFlush) {
2427
+ this.refilterAfterAsyncFlush = false;
2428
+ this.postEditBatch.needsRefilter = true;
2429
+ }
2430
+ this.addToPrimaryKeyLookup(result?.add);
2431
+ this.reportTrackedRowUpdates(result?.update);
2432
+ });
2334
2433
  }
2335
2434
  finally {
2336
- this.endOffScreenRowUpdateTracking(tracking);
2435
+ this.pendingAsyncTransactions--;
2436
+ for (const node of trackedNodes) {
2437
+ const count = this.pendingAsyncRowNodes.get(node) ?? 0;
2438
+ if (count > 1) {
2439
+ this.pendingAsyncRowNodes.set(node, count - 1);
2440
+ }
2441
+ else {
2442
+ this.pendingAsyncRowNodes.delete(node);
2443
+ }
2444
+ }
2445
+ this.releaseTrackedRows();
2337
2446
  }
2338
2447
  callback(result);
2339
2448
  };
2340
2449
  return agGridApi.applyTransactionAsync(transaction, wrappedCallback);
2341
2450
  }
2342
- beginOffScreenRowUpdateTracking(updateRows) {
2451
+ trackRowUpdates(updateRows) {
2343
2452
  if (!updateRows?.length || !this.isListeningToAgGridRowNodeEvents) {
2344
- return undefined;
2453
+ return [];
2345
2454
  }
2346
2455
  const primaryKey = this.adaptableOptions.primaryKey;
2347
- const oldDataByPk = new Map();
2456
+ const trackedNodes = [];
2348
2457
  for (const row of updateRows) {
2349
- if (row == null || row[primaryKey] == null) {
2458
+ const primaryKeyValue = row?.[primaryKey];
2459
+ if (primaryKeyValue == null) {
2350
2460
  continue;
2351
2461
  }
2352
- const node = this.getRowNodeForPrimaryKey(row[primaryKey]);
2353
- if (node?.data) {
2354
- oldDataByPk.set(row[primaryKey], { ...node.data });
2462
+ const node = this.getRowNodeForPrimaryKey(primaryKeyValue);
2463
+ if (!node?.data) {
2464
+ continue;
2355
2465
  }
2466
+ if (node.data === row) {
2467
+ this.warnSameObjectUpdate();
2468
+ continue;
2469
+ }
2470
+ if (!this.trackedRowData.has(node)) {
2471
+ this.trackedRowData.set(node, node.data);
2472
+ }
2473
+ trackedNodes.push(node);
2356
2474
  }
2357
- const tracking = {
2358
- seenIds: new Set(),
2359
- oldDataByPk,
2360
- };
2361
- this.offScreenRowUpdateTrackers.push(tracking);
2362
- return tracking;
2363
- }
2364
- endOffScreenRowUpdateTracking(tracking) {
2365
- if (!tracking) {
2366
- return;
2367
- }
2368
- const index = this.offScreenRowUpdateTrackers.lastIndexOf(tracking);
2369
- if (index >= 0) {
2370
- this.offScreenRowUpdateTrackers.splice(index, 1);
2371
- }
2475
+ return trackedNodes;
2372
2476
  }
2373
- emitOffScreenRowUpdates(tracking, updatedNodes) {
2374
- if (!tracking || !updatedNodes?.length) {
2477
+ reportTrackedRowUpdates(updatedNodes) {
2478
+ if (!updatedNodes?.length || this.trackedRowData.size === 0) {
2375
2479
  return;
2376
2480
  }
2377
2481
  for (const node of updatedNodes) {
2378
- if (!node || (node.id != null && tracking.seenIds.has(node.id))) {
2379
- continue;
2380
- }
2381
- const primaryKeyValue = this.getPrimaryKeyValueFromRowNode(node);
2382
- const oldData = tracking.oldDataByPk.get(primaryKeyValue);
2383
- if (oldData == null) {
2482
+ const reportedData = this.trackedRowData.get(node);
2483
+ if (reportedData === undefined || reportedData === node.data) {
2384
2484
  continue;
2385
2485
  }
2386
- this.onRowDataChanged({ rowNode: node, oldData, newData: node.data });
2486
+ this.trackedRowData.set(node, node.data);
2487
+ this.onRowDataChanged({ rowNode: node, oldData: reportedData, newData: node.data });
2488
+ }
2489
+ }
2490
+ releaseTrackedRows() {
2491
+ if (this.syncTransactionDepth === 0 && this.pendingAsyncTransactions === 0) {
2492
+ this.trackedRowData.clear();
2387
2493
  }
2388
2494
  }
2495
+ warnSameObjectUpdate() {
2496
+ if (this.hasWarnedSameObjectUpdate) {
2497
+ return;
2498
+ }
2499
+ this.hasWarnedSameObjectUpdate = true;
2500
+ this.logger.consoleWarn('A row passed to updateGridData, addOrUpdateGridData or manageGridData is the same object as the row in the grid. ' +
2501
+ 'Changes made to that object in place cannot be detected, so no Cell Changed Event, Flashing Cell or Alert is raised for them. ' +
2502
+ 'Pass a new object for each updated row instead.');
2503
+ }
2389
2504
  updateRows(dataRows, dataUpdateConfig) {
2390
2505
  if (this.hasAutogeneratedPrimaryKey) {
2391
2506
  this.addSyntheticPrimaryKeyIfMissing(dataRows);
@@ -2589,15 +2704,71 @@ export class AdaptableAgGrid {
2589
2704
  }
2590
2705
  }
2591
2706
  getRowNodeForPrimaryKey(primaryKeyValue) {
2592
- if (this.useRowNodeLookUp) {
2593
- return this.agGridAdapter.getAgGridApi().getRowNode(primaryKeyValue);
2707
+ if (primaryKeyValue == null) {
2708
+ return undefined;
2594
2709
  }
2595
- else {
2596
- this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
2597
- if (primaryKeyValue == this.getPrimaryKeyValueFromRowNode(rowNode)) {
2598
- return rowNode;
2710
+ const rowNode = this.agGridAdapter
2711
+ .getAgGridApi()
2712
+ .getRowNode(typeof primaryKeyValue === 'number' ? `${primaryKeyValue}` : primaryKeyValue);
2713
+ if (rowNode && this.readPrimaryKeyValue(rowNode) == primaryKeyValue) {
2714
+ return rowNode;
2715
+ }
2716
+ if (this.isRowIdPrimaryKey &&
2717
+ this.getAgGridRowModelType() === 'clientSide' &&
2718
+ !this.agGridAdapter.getGridOption('treeData')) {
2719
+ return undefined;
2720
+ }
2721
+ return this.getRowNodeFromPrimaryKeyLookup(primaryKeyValue);
2722
+ }
2723
+ readPrimaryKeyValue(rowNode) {
2724
+ const value = rowNode.data?.[this.adaptableOptions.primaryKey];
2725
+ return value !== undefined ? value : this.getPrimaryKeyValueFromRowNode(rowNode);
2726
+ }
2727
+ getRowNodeFromPrimaryKeyLookup(primaryKeyValue) {
2728
+ const agGridApi = this.agGridAdapter.getAgGridApi();
2729
+ const key = String(primaryKeyValue);
2730
+ const lookup = this.primaryKeyLookup;
2731
+ const cached = lookup?.rowNodeByPrimaryKey.get(key);
2732
+ if (cached &&
2733
+ agGridApi.getRowNode(cached.id) === cached &&
2734
+ this.readPrimaryKeyValue(cached) == primaryKeyValue) {
2735
+ return cached;
2736
+ }
2737
+ if (lookup?.builtInTurn) {
2738
+ return undefined;
2739
+ }
2740
+ const rowNodeByPrimaryKey = new Map();
2741
+ agGridApi.forEachNode((rowNode) => {
2742
+ if (rowNode.data && !rowNode.group) {
2743
+ const value = this.readPrimaryKeyValue(rowNode);
2744
+ if (value != null) {
2745
+ rowNodeByPrimaryKey.set(String(value), rowNode);
2599
2746
  }
2600
- });
2747
+ }
2748
+ });
2749
+ const builtLookup = { rowNodeByPrimaryKey, builtInTurn: true };
2750
+ this.primaryKeyLookup = builtLookup;
2751
+ queueMicrotask(() => {
2752
+ builtLookup.builtInTurn = false;
2753
+ });
2754
+ const found = rowNodeByPrimaryKey.get(key);
2755
+ if (found && !this.hasLoggedPrimaryKeyLookupFallback) {
2756
+ this.hasLoggedPrimaryKeyLookupFallback = true;
2757
+ this.logger.consoleWarn(`The row id given by getRowId is not the primary key value ('${this.adaptableOptions.primaryKey}'), so rows are looked up by primary key through a slower search. ` +
2758
+ 'Return the primary key value from getRowId to avoid it.');
2759
+ }
2760
+ return found;
2761
+ }
2762
+ addToPrimaryKeyLookup(addedRowNodes) {
2763
+ const lookup = this.primaryKeyLookup;
2764
+ if (!lookup || !addedRowNodes?.length) {
2765
+ return;
2766
+ }
2767
+ for (const rowNode of addedRowNodes) {
2768
+ const value = this.readPrimaryKeyValue(rowNode);
2769
+ if (value != null) {
2770
+ lookup.rowNodeByPrimaryKey.set(String(value), rowNode);
2771
+ }
2601
2772
  }
2602
2773
  }
2603
2774
  hideColumn(columnId) {
@@ -3174,26 +3345,13 @@ export class AdaptableAgGrid {
3174
3345
  return returnValues;
3175
3346
  }
3176
3347
  getRowNodesForPrimaryKeys(primaryKeyValues) {
3177
- let rowNodes = [];
3178
- if (this.useRowNodeLookUp) {
3179
- primaryKeyValues.forEach((pkValue) => {
3180
- const rowNode = this.agGridAdapter.getAgGridApi().getRowNode(pkValue);
3181
- if (rowNode) {
3182
- rowNodes.push(rowNode);
3183
- }
3184
- });
3185
- }
3186
- else {
3187
- primaryKeyValues.forEach((pkValue) => {
3188
- let foundRow = false;
3189
- this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
3190
- if (!foundRow && pkValue == this.getPrimaryKeyValueFromRowNode(rowNode)) {
3191
- rowNodes.push(rowNode);
3192
- foundRow = true;
3193
- }
3194
- });
3195
- });
3196
- }
3348
+ const rowNodes = [];
3349
+ primaryKeyValues.forEach((pkValue) => {
3350
+ const rowNode = this.getRowNodeForPrimaryKey(pkValue);
3351
+ if (rowNode) {
3352
+ rowNodes.push(rowNode);
3353
+ }
3354
+ });
3197
3355
  return rowNodes;
3198
3356
  }
3199
3357
  getRowNodeByIndex(index) {
@@ -3208,7 +3366,38 @@ export class AdaptableAgGrid {
3208
3366
  this.logger.warn(`updateCell() - rowNode not found for primaryKeyValue: ${cellUpdateRequest.primaryKeyValue}`);
3209
3367
  return;
3210
3368
  }
3211
- rowNode.setDataValue(cellUpdateRequest.columnId, cellUpdateRequest.newValue, 'edit');
3369
+ const outerCapture = this.updateCellCapture;
3370
+ const capture = {
3371
+ events: [],
3372
+ reportedByRowNode: new Map(),
3373
+ };
3374
+ this.updateCellCapture = capture;
3375
+ try {
3376
+ rowNode.setDataValue(cellUpdateRequest.columnId, cellUpdateRequest.newValue, 'edit');
3377
+ }
3378
+ finally {
3379
+ this.updateCellCapture = outerCapture;
3380
+ }
3381
+ if (!this.isListeningToAgGridRowNodeEvents) {
3382
+ return;
3383
+ }
3384
+ for (const event of capture.events) {
3385
+ const { node, column } = event;
3386
+ if (!node || !column || getPinnedCopySource(node)) {
3387
+ continue;
3388
+ }
3389
+ const colId = column.getColId();
3390
+ if (capture.reportedByRowNode.get(node)?.has(colId)) {
3391
+ continue;
3392
+ }
3393
+ this.noteCellChangeReported(node, colId);
3394
+ this.onCellDataChanged({
3395
+ rowNode: node,
3396
+ oldValue: event.oldValue,
3397
+ newValue: event.newValue,
3398
+ colId,
3399
+ });
3400
+ }
3212
3401
  }
3213
3402
  forAllRowNodesDo(func, config) {
3214
3403
  this.agGridAdapter.getAgGridApi().forEachNode((rowNode, rowIndex) => {
@@ -3732,6 +3921,13 @@ export class AdaptableAgGrid {
3732
3921
  this.agGridModulesAdapter?.destroy();
3733
3922
  this.agGridModulesAdapter = null;
3734
3923
  this.isListeningToAgGridRowNodeEvents = false;
3924
+ this.trackedRowData.clear();
3925
+ this.pendingAsyncRowNodes.clear();
3926
+ this.reportedCellChanges.clear();
3927
+ this.updateCellCapture = undefined;
3928
+ this.pendingPinnedCopyRefreshes.clear();
3929
+ this.primaryKeyLookup = undefined;
3930
+ this.dataBackedColumnsCache = undefined;
3735
3931
  this.emitter.destroy();
3736
3932
  this.emitter = null;
3737
3933
  this.adaptableOptions = null;
@@ -3923,7 +4119,17 @@ export class AdaptableAgGrid {
3923
4119
  }
3924
4120
  return null;
3925
4121
  }
3926
- onRowDataChanged({ rowNode, oldData, newData, }) {
4122
+ getDataBackedColumns() {
4123
+ const columns = this.api.columnApi.getColumns();
4124
+ if (this.dataBackedColumnsCache?.columns !== columns) {
4125
+ this.dataBackedColumnsCache = {
4126
+ columns,
4127
+ dataBackedColumns: getDataBackedColumns(columns, !!this.agGridAdapter.getGridOption('suppressFieldDotNotation')),
4128
+ };
4129
+ }
4130
+ return this.dataBackedColumnsCache.dataBackedColumns;
4131
+ }
4132
+ onRowDataChanged({ rowNode, oldData, newData, deferRefilter = false, }) {
3927
4133
  if (oldData == null || oldData == undefined) {
3928
4134
  return;
3929
4135
  }
@@ -3934,31 +4140,34 @@ export class AdaptableAgGrid {
3934
4140
  if (primaryKeyValue == null) {
3935
4141
  return;
3936
4142
  }
3937
- let cellDataChangedInfos = [];
3938
- Object.keys(oldData).forEach((key) => {
3939
- if (this.api.columnApi.isColumnInGrid(key)) {
3940
- const oldValue = oldData[key];
3941
- const newValue = newData[key];
3942
- if (oldValue != newValue) {
3943
- const cellDataChangedInfo = this.api.internalApi.buildCellDataChangedInfo({
3944
- oldValue: oldValue,
3945
- newValue: newValue,
3946
- column: this.api.columnApi.getColumnWithColumnId(key),
3947
- primaryKeyValue: primaryKeyValue,
3948
- rowNode: rowNode,
3949
- trigger: 'tick',
3950
- });
3951
- if (this.isUndoChange(cellDataChangedInfo)) {
3952
- cellDataChangedInfo.trigger = 'undo';
3953
- }
3954
- cellDataChangedInfos.push(cellDataChangedInfo);
3955
- }
4143
+ const internalApi = this.api.internalApi;
4144
+ const cellDataChangedInfos = [];
4145
+ for (const { column, field, isNested } of this.getDataBackedColumns()) {
4146
+ const oldValue = isNested ? internalApi.getValueUsingField(oldData, field) : oldData[field];
4147
+ const newValue = isNested ? internalApi.getValueUsingField(newData, field) : newData?.[field];
4148
+ if (areCellValuesEqual(oldValue, newValue)) {
4149
+ continue;
3956
4150
  }
3957
- });
3958
- this.performPostEditChecks(rowNode, cellDataChangedInfos);
4151
+ const cellDataChangedInfo = internalApi.buildCellDataChangedInfo({
4152
+ oldValue: oldValue,
4153
+ newValue: newValue,
4154
+ column,
4155
+ primaryKeyValue: primaryKeyValue,
4156
+ rowNode: rowNode,
4157
+ trigger: 'tick',
4158
+ });
4159
+ if (this.isUndoChange(cellDataChangedInfo)) {
4160
+ cellDataChangedInfo.trigger = 'undo';
4161
+ }
4162
+ cellDataChangedInfos.push(cellDataChangedInfo);
4163
+ }
4164
+ if (cellDataChangedInfos.length === 0) {
4165
+ return;
4166
+ }
4167
+ this.performPostEditChecks(rowNode, cellDataChangedInfos, { oldData, deferRefilter });
3959
4168
  }
3960
4169
  onCellDataChanged({ rowNode, oldValue, newValue, colId, }) {
3961
- if (oldValue == newValue) {
4170
+ if (areCellValuesEqual(oldValue, newValue)) {
3962
4171
  return;
3963
4172
  }
3964
4173
  const abColumn = this.api.columnApi.getColumnWithColumnId(colId);
@@ -3998,23 +4207,24 @@ export class AdaptableAgGrid {
3998
4207
  const undoChange = this.api.internalApi.getDataService().extractUndoChange(dataChange);
3999
4208
  return !!undoChange;
4000
4209
  }
4001
- performPostEditChecks(rowNode, cellDataChangedInfos) {
4210
+ performPostEditChecks(rowNode, cellDataChangedInfos, options) {
4002
4211
  const recorder = getPerfRecorder(this.adaptableOptions?.adaptableId);
4003
4212
  if (!recorder) {
4004
- this.performPostEditChecksNow(rowNode, cellDataChangedInfos);
4213
+ this.performPostEditChecksNow(rowNode, cellDataChangedInfos, options);
4005
4214
  return;
4006
4215
  }
4007
4216
  const start = performance.now();
4008
4217
  try {
4009
- this.performPostEditChecksNow(rowNode, cellDataChangedInfos);
4218
+ this.performPostEditChecksNow(rowNode, cellDataChangedInfos, options);
4010
4219
  }
4011
4220
  finally {
4012
4221
  recorder.count('cellChanges', cellDataChangedInfos.length);
4013
4222
  recorder.add('dataChange', 'dataChange', start, describeDataChangePerf);
4014
4223
  }
4015
4224
  }
4016
- performPostEditChecksNow(rowNode, cellDataChangedInfos) {
4017
- cellDataChangedInfos = expandCellDataChangedInfosWithCalculatedColumns(this.api, cellDataChangedInfos);
4225
+ performPostEditChecksNow(rowNode, cellDataChangedInfos, options) {
4226
+ const batch = this.postEditBatch;
4227
+ cellDataChangedInfos = expandCellDataChangedInfosWithCalculatedColumns(this.api, cellDataChangedInfos, options?.oldData);
4018
4228
  cellDataChangedInfos.forEach((cellDataChangedInfo) => {
4019
4229
  if (cellDataChangedInfo.trigger === 'undo') {
4020
4230
  this.logger.info(`Data change reverted: column="${cellDataChangedInfo.column}", primaryKey="${cellDataChangedInfo.primaryKeyValue}", from=${cellDataChangedInfo.newValue} to=${cellDataChangedInfo.oldValue}`);
@@ -4022,7 +4232,12 @@ export class AdaptableAgGrid {
4022
4232
  if (cellDataChangedInfo.trigger === 'edit' ||
4023
4233
  cellDataChangedInfo.trigger === 'undo' ||
4024
4234
  cellDataChangedInfo.trigger === 'tick') {
4025
- this.checkIfChangedCellCurrentlySelected(cellDataChangedInfo);
4235
+ if (batch) {
4236
+ this.recordChangedCellForSelection(batch, cellDataChangedInfo);
4237
+ }
4238
+ else {
4239
+ this.checkIfChangedCellCurrentlySelected(cellDataChangedInfo);
4240
+ }
4026
4241
  }
4027
4242
  this.DataService.CreateCellDataChangedEvent(cellDataChangedInfo);
4028
4243
  this.updateMinMaxCachedValueForColumn(cellDataChangedInfo);
@@ -4033,17 +4248,102 @@ export class AdaptableAgGrid {
4033
4248
  const isGridFilterActive = !!gridFilterApi.getCurrentGridFilterExpression();
4034
4249
  const isColumnFilterActive = colIds.some((colId) => columnFilterApi.isColumnFilterActiveForColumn(colId));
4035
4250
  const shouldFilter = isGridFilterActive || isColumnFilterActive;
4036
- if (shouldFilter) {
4251
+ if (!shouldFilter) {
4252
+ return;
4253
+ }
4254
+ if (batch) {
4255
+ batch.needsRefilter = true;
4256
+ }
4257
+ else if (options?.deferRefilter) {
4258
+ this.refilterAfterAsyncFlush = true;
4259
+ }
4260
+ else {
4261
+ this.filterOnDataChange();
4262
+ }
4263
+ }
4264
+ runPostEditBatch(fn) {
4265
+ if (this.postEditBatch) {
4266
+ return fn();
4267
+ }
4268
+ const batch = {
4269
+ needsRefilter: false,
4270
+ refreshAllCells: false,
4271
+ allRowsColumnIds: new Set(),
4272
+ changedCellKeys: new Set(),
4273
+ changedRowKeys: new Set(),
4274
+ };
4275
+ this.postEditBatch = batch;
4276
+ try {
4277
+ return fn();
4278
+ }
4279
+ finally {
4280
+ this.postEditBatch = undefined;
4281
+ this.flushPostEditBatch(batch);
4282
+ }
4283
+ }
4284
+ flushPostEditBatch(batch) {
4285
+ if (!this.isListeningToAgGridRowNodeEvents) {
4286
+ return;
4287
+ }
4288
+ if (batch.refreshAllCells) {
4289
+ this.agGridAdapter.getAgGridApi().refreshCells({ force: true, suppressFlash: true });
4290
+ }
4291
+ else if (batch.allRowsColumnIds.size > 0) {
4292
+ this.refreshColumns([...batch.allRowsColumnIds], true, true);
4293
+ }
4294
+ if (batch.selection) {
4295
+ const { cells, rows } = batch.selection;
4296
+ if (batch.changedCellKeys.size > 0 &&
4297
+ cells.some((gridCell) => batch.changedCellKeys.has(getChangedCellKey(gridCell.primaryKeyValue, gridCell.column?.columnId)))) {
4298
+ this.debouncedSetSelectedCells();
4299
+ }
4300
+ if (batch.changedRowKeys.size > 0 &&
4301
+ rows.some((gridRow) => batch.changedRowKeys.has(String(gridRow.primaryKeyValue)))) {
4302
+ this.debouncedSetSelectedRows();
4303
+ }
4304
+ }
4305
+ if (batch.needsRefilter) {
4037
4306
  this.filterOnDataChange();
4038
4307
  }
4039
4308
  }
4309
+ recordChangedCellForSelection(batch, cellDataChangedInfo) {
4310
+ if (!batch.selection) {
4311
+ batch.selection = {
4312
+ cells: this.api.gridApi.getSelectedCellInfo()?.gridCells ?? [],
4313
+ rows: this.api.gridApi.getSelectedRowInfo()?.gridRows ?? [],
4314
+ };
4315
+ }
4316
+ const { cells, rows } = batch.selection;
4317
+ if (cells.length > 0) {
4318
+ batch.changedCellKeys.add(getChangedCellKey(cellDataChangedInfo.primaryKeyValue, cellDataChangedInfo.column?.columnId));
4319
+ }
4320
+ if (rows.length > 0) {
4321
+ batch.changedRowKeys.add(String(cellDataChangedInfo.primaryKeyValue));
4322
+ }
4323
+ }
4324
+ isRowNodeRendered(rowNode) {
4325
+ if (rowNode.rowPinned != null) {
4326
+ return true;
4327
+ }
4328
+ const batch = this.postEditBatch;
4329
+ if (!batch) {
4330
+ return this.agGridAdapter.isVisibleNode(rowNode);
4331
+ }
4332
+ if (!batch.renderedRowIds) {
4333
+ batch.renderedRowIds = new Set(this.agGridAdapter
4334
+ .getAgGridApi()
4335
+ .getRenderedNodes()
4336
+ .map((renderedNode) => renderedNode.id));
4337
+ }
4338
+ return batch.renderedRowIds.has(rowNode.id);
4339
+ }
4040
4340
  collectPostEditRefreshScope(rowNode, cellDataChangedInfos) {
4041
4341
  const scope = {
4042
4342
  wholeRow: false,
4043
4343
  columnIds: new Set(),
4044
4344
  allRowsColumnIds: new Set(),
4045
4345
  };
4046
- const isVisible = this.agGridAdapter.isVisibleNode(rowNode);
4346
+ const isVisible = this.getRenderedCopiesOfRow(rowNode).length > 0;
4047
4347
  if (isVisible && cellDataChangedInfos.length > 0) {
4048
4348
  this.checkFormatColumnExpressionStyleChanges(scope, cellDataChangedInfos);
4049
4349
  if (!scope.wholeRow) {
@@ -4087,22 +4387,65 @@ export class AdaptableAgGrid {
4087
4387
  }
4088
4388
  applyPostEditRefresh(rowNode, scope) {
4089
4389
  const { wholeRow, columnIds, allRowsColumnIds } = scope;
4090
- if (allRowsColumnIds.size > 0 && wholeRow) {
4390
+ const batch = this.postEditBatch;
4391
+ const pinnedSibling = rowNode.pinnedSibling;
4392
+ if (pinnedSibling &&
4393
+ pinnedSibling.data !== rowNode.data &&
4394
+ hasLocalEventService(pinnedSibling) &&
4395
+ (wholeRow || columnIds.size > 0 || allRowsColumnIds.size > 0)) {
4396
+ this.pendingPinnedCopyRefreshes.set(pinnedSibling, {
4397
+ wholeRow,
4398
+ columnIds: new Set([...columnIds, ...allRowsColumnIds]),
4399
+ });
4400
+ }
4401
+ if (batch && allRowsColumnIds.size > 0) {
4402
+ if (wholeRow) {
4403
+ batch.refreshAllCells = true;
4404
+ return;
4405
+ }
4406
+ allRowsColumnIds.forEach((columnId) => batch.allRowsColumnIds.add(columnId));
4407
+ }
4408
+ else if (allRowsColumnIds.size > 0 && wholeRow) {
4091
4409
  this.agGridAdapter.getAgGridApi().refreshCells({ force: true, suppressFlash: true });
4092
4410
  return;
4093
4411
  }
4094
- if (allRowsColumnIds.size > 0) {
4412
+ else if (allRowsColumnIds.size > 0) {
4095
4413
  this.refreshColumns([...allRowsColumnIds, ...columnIds], true, true);
4096
4414
  return;
4097
4415
  }
4416
+ const rowNodes = this.getRenderedCopiesOfRow(rowNode).filter((node) => !this.pendingPinnedCopyRefreshes.has(node));
4417
+ this.refreshRenderedRows(rowNodes, wholeRow, columnIds);
4418
+ }
4419
+ applyPendingPinnedCopyRefresh(pinnedCopy) {
4420
+ const pending = this.pendingPinnedCopyRefreshes.get(pinnedCopy);
4421
+ if (!pending) {
4422
+ return;
4423
+ }
4424
+ this.pendingPinnedCopyRefreshes.delete(pinnedCopy);
4425
+ this.refreshRenderedRows([pinnedCopy], pending.wholeRow, pending.columnIds);
4426
+ }
4427
+ refreshRenderedRows(rowNodes, wholeRow, columnIds) {
4428
+ if (rowNodes.length === 0) {
4429
+ return;
4430
+ }
4098
4431
  if (wholeRow) {
4099
- this.redrawRow(rowNode);
4432
+ this.redrawRows(rowNodes);
4100
4433
  return;
4101
4434
  }
4102
- if (columnIds.size > 0 && this.agGridAdapter.isVisibleNode(rowNode)) {
4103
- this.refreshCells(rowNode, Array.from(columnIds), true, true);
4435
+ if (columnIds.size > 0) {
4436
+ this.agGridAdapter.getAgGridApi().refreshCells({
4437
+ rowNodes,
4438
+ columns: Array.from(columnIds),
4439
+ force: true,
4440
+ suppressFlash: true,
4441
+ });
4104
4442
  }
4105
4443
  }
4444
+ getRenderedCopiesOfRow(rowNode) {
4445
+ const pinnedSibling = rowNode.pinnedSibling;
4446
+ const rowNodes = pinnedSibling ? [rowNode, pinnedSibling] : [rowNode];
4447
+ return rowNodes.filter((node) => this.isRowNodeRendered(node));
4448
+ }
4106
4449
  checkStyledColumnComparisonChanges(dataChangedScope, cellDataChangedInfos) {
4107
4450
  this.api.styledColumnApi.getStyledColumns().forEach((sc) => {
4108
4451
  let columnComparison = this.api.styledColumnApi.internalApi.getColumnComparisonForStyledColumn(sc);