@genesislcap/grid-pro 14.325.1 → 14.326.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +49 -0
  2. package/dist/custom-elements.json +236 -0
  3. package/dist/dts/cell-renderers/action.renderer.d.ts.map +1 -1
  4. package/dist/dts/grid-pro.d.ts +57 -0
  5. package/dist/dts/grid-pro.d.ts.map +1 -1
  6. package/dist/dts/state-persistence/kv-state.d.ts +1 -0
  7. package/dist/dts/state-persistence/kv-state.d.ts.map +1 -1
  8. package/dist/dts/state-persistence/local-state.d.ts +1 -0
  9. package/dist/dts/state-persistence/local-state.d.ts.map +1 -1
  10. package/dist/dts/state-persistence/state-persistence.d.ts +5 -0
  11. package/dist/dts/state-persistence/state-persistence.d.ts.map +1 -1
  12. package/dist/dts/utils/array.d.ts +14 -0
  13. package/dist/dts/utils/array.d.ts.map +1 -1
  14. package/dist/esm/cell-renderers/action.renderer.js +5 -3
  15. package/dist/esm/cell-renderers/boolean.renderer.js +4 -3
  16. package/dist/esm/grid-pro.js +156 -2
  17. package/dist/esm/state-persistence/kv-state.js +5 -0
  18. package/dist/esm/state-persistence/local-state.js +7 -0
  19. package/dist/esm/utils/array.js +31 -0
  20. package/dist/grid-pro.api.json +406 -0
  21. package/dist/grid-pro.d.ts +80 -0
  22. package/docs/api/grid-pro.convertcoldefstocolumnstates.md +56 -0
  23. package/docs/api/grid-pro.convertcoldeftocolumnstate.md +56 -0
  24. package/docs/api/grid-pro.gridpro.defaultcolumnconfig.md +13 -0
  25. package/docs/api/grid-pro.gridpro.deletecolumnstate.md +58 -0
  26. package/docs/api/grid-pro.gridpro.md +71 -0
  27. package/docs/api/grid-pro.gridpro.sizecolumnstocontent.md +13 -0
  28. package/docs/api/grid-pro.gridpro.sizecolumnstofit.md +13 -0
  29. package/docs/api/grid-pro.kvstoragestatepersistence.deletecolumnstate.md +50 -0
  30. package/docs/api/grid-pro.kvstoragestatepersistence.md +12 -0
  31. package/docs/api/grid-pro.localstoragestatepersistence.deletecolumnstate.md +50 -0
  32. package/docs/api/grid-pro.localstoragestatepersistence.md +12 -0
  33. package/docs/api/grid-pro.md +22 -0
  34. package/docs/api/grid-pro.statepersistence.deletecolumnstate.md +52 -0
  35. package/docs/api/grid-pro.statepersistence.md +11 -0
  36. package/docs/api-report.md.api.md +15 -0
  37. package/package.json +13 -13
@@ -24,7 +24,7 @@ import { AgGridTheme, agThemeFontsId, agThemeTokenMapClassname, DEFAULT_STATUS_B
24
24
  import { StatePersistence } from './state-persistence';
25
25
  import { LabelValueStatusBarComponent, LoadMoreStatusBarComponent, PaginationStatusBarComponent, ReloadStatusBarComponent, } from './status-bar-components';
26
26
  import { ErrorTooltip } from './tooltips';
27
- import { convertToKebabCase, logger, mergeAndDedupColDefWithColumnState } from './utils';
27
+ import { convertToKebabCase, logger, mergeAndDedupColDefWithColumnState, convertColDefsToColumnStates, } from './utils';
28
28
  GridProGenesisDatasource;
29
29
  GridProClientSideDatasource;
30
30
  GridProServerSideDatasource;
@@ -79,6 +79,9 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
79
79
  }
80
80
  constructor() {
81
81
  super();
82
+ // Cache for total column width to avoid repeated calculations
83
+ this.cachedTotalColumnWidth = null;
84
+ this.columnCount = 0;
82
85
  this.gridErrorItems = [];
83
86
  // Genesis-specific attrs
84
87
  this.autoCellRendererByType = false;
@@ -90,6 +93,18 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
90
93
  * in local storage if you are using `persist-column-state-key`.
91
94
  */
92
95
  this.gridAutosizingEnabled = false;
96
+ /**
97
+ * Boolean attribute to control whether the grid automatically sizes columns to fit their content.
98
+ * This will call AG Grid's autoSizeColumns() method to automatically adjust column widths based on content.
99
+ * @public
100
+ */
101
+ this.sizeColumnsToContent = false;
102
+ /**
103
+ * Boolean attribute to adjust the size of columns to fit the available horizontal space.
104
+ * This will call AG Grid's sizeColumnsToFit() method.
105
+ * @public
106
+ */
107
+ this.sizeColumnsToFit = false;
93
108
  /**
94
109
  * The index to add new rows to when using `applyTransaction` or `applyTransactionAsync`
95
110
  */
@@ -122,6 +137,10 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
122
137
  * If true, will enable row flashing for all rows for `add` async transactions
123
138
  */
124
139
  this.enableRowFlashing = false;
140
+ /**
141
+ * The default column config to reset to when deleteColumnState is called.
142
+ */
143
+ this.defaultColumnConfig = [];
125
144
  this.gridFontFace = defaultAgGridFontFace;
126
145
  this.columnComponentName = 'grid-pro-column';
127
146
  this.theme = AgGridTheme.alpine;
@@ -262,6 +281,7 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
262
281
  return;
263
282
  this.initialised = false;
264
283
  (_a = this.gridApi) === null || _a === void 0 ? void 0 : _a.destroy();
284
+ this.invalidateColumnWidthCache();
265
285
  // Clear registered events when grid is destroyed
266
286
  this.registeredGridEvents.clear();
267
287
  });
@@ -432,6 +452,35 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
432
452
  return this.columnState;
433
453
  });
434
454
  }
455
+ /**
456
+ * Deletes the saved column state for the current grid
457
+ * @param resetToDefault - Whether to reset columns to their default configuration. Defaults to true.
458
+ * @remarks This removes the persisted column state from storage, allowing the grid to use default column configuration
459
+ * @public
460
+ */
461
+ deleteColumnState() {
462
+ return __awaiter(this, arguments, void 0, function* (resetToDefault = true) {
463
+ var _a;
464
+ if (this.statePersistanceEnabled()) {
465
+ yield this.statePersistence.deleteColumnState(this.persistColumnStateKey);
466
+ this.columnState = [];
467
+ }
468
+ if (resetToDefault && this.columnApi) {
469
+ if (((_a = this.defaultColumnConfig) === null || _a === void 0 ? void 0 : _a.length) > 0) {
470
+ // Convert ColDef[] to ColumnState[] using utility function
471
+ const columnState = convertColDefsToColumnStates(this.defaultColumnConfig);
472
+ this.columnApi.applyColumnState({
473
+ state: columnState,
474
+ applyOrder: true,
475
+ });
476
+ }
477
+ else {
478
+ this.columnApi.resetColumnState();
479
+ }
480
+ this.handleColumnSizing();
481
+ }
482
+ });
483
+ }
435
484
  restoreColumnState() {
436
485
  return __awaiter(this, void 0, void 0, function* () {
437
486
  var _a;
@@ -495,6 +544,7 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
495
544
  const gridOnChangeCallback = () => {
496
545
  debounceSaveColumnState();
497
546
  this.debouncedColumnAutosize.bind(this)();
547
+ this.invalidateColumnWidthCache();
498
548
  };
499
549
  Array.from(this.attributes).forEach((attribute) => {
500
550
  const attrName = this.agPropertiesMap[attribute.name];
@@ -502,7 +552,7 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
502
552
  return;
503
553
  this.agAttributes[attrName] = attribute.value;
504
554
  });
505
- const { columnDefs, components, defaultColDef, getRowId, onGridReady, onFilterChanged } = options, rest = __rest(options, ["columnDefs", "components", "defaultColDef", "getRowId", "onGridReady", "onFilterChanged"]);
555
+ const { columnDefs, components, defaultColDef, getRowId, onGridReady, onFilterChanged, onFirstDataRendered } = options, rest = __rest(options, ["columnDefs", "components", "defaultColDef", "getRowId", "onGridReady", "onFilterChanged", "onFirstDataRendered"]);
506
556
  const derivedOptions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.gridOptionsConfig), { defaultColDef: Object.assign({ enableCellChangeFlash: this.enableCellFlashing, filter: true, resizable: true, sortable: true }, defaultColDef), components: this.combineAllGridComponents(components), suppressDragLeaveHidesColumns: true }), this.eventsAndCallbacks), { onGridReady: (event) => {
507
557
  this.gridApi = event.api;
508
558
  this.columnApi = event.columnApi;
@@ -529,6 +579,13 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
529
579
  this.restoreColumnState.bind(this)();
530
580
  this.restoreCachedFilterConfig.bind(this)();
531
581
  this.debouncedColumnAutosize.bind(this)();
582
+ }, onFirstDataRendered: (event) => {
583
+ // Handle column sizing
584
+ this.handleColumnSizing();
585
+ // Call the original onFirstDataRendered if provided
586
+ if (onFirstDataRendered) {
587
+ onFirstDataRendered(event);
588
+ }
532
589
  }, onColumnPinned: gridOnChangeCallback, onColumnResized: gridOnChangeCallback, onColumnMoved: gridOnChangeCallback, onDisplayedColumnsChanged: gridOnChangeCallback, onFilterChanged: (filterChangedEvent) => {
533
590
  debouceSaveFiltermodel();
534
591
  if (onFilterChanged) {
@@ -757,6 +814,94 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
757
814
  };
758
815
  }
759
816
  }
817
+ /**
818
+ * Handles column sizing based on sizeColumnsToContent and sizeColumnsToFit attributes
819
+ * @private
820
+ */
821
+ handleColumnSizing() {
822
+ if (!this.sizeColumnsToContent && !this.sizeColumnsToFit)
823
+ return;
824
+ if (this.sizeColumnsToContent && this.sizeColumnsToFit && this.columnApi && this.gridApi) {
825
+ this.handleBothSizingModes();
826
+ }
827
+ else {
828
+ this.handleIndividualSizingModes();
829
+ }
830
+ }
831
+ /**
832
+ * Handles when both sizeColumnsToContent and sizeColumnsToFit are enabled
833
+ * @private
834
+ */
835
+ handleBothSizingModes() {
836
+ const totalColumnWidth = this.calculateTotalColumnWidth();
837
+ const gridWidth = this.getGridWidth();
838
+ if (totalColumnWidth > gridWidth) {
839
+ if (!this.columnApi)
840
+ return;
841
+ this.columnApi.autoSizeAllColumns();
842
+ }
843
+ else {
844
+ if (!this.gridApi)
845
+ return;
846
+ this.gridApi.sizeColumnsToFit();
847
+ }
848
+ }
849
+ /**
850
+ * Handles individual sizing modes when only one is enabled
851
+ * @private
852
+ */
853
+ handleIndividualSizingModes() {
854
+ if (this.sizeColumnsToContent && this.columnApi) {
855
+ this.columnApi.autoSizeAllColumns();
856
+ }
857
+ if (this.sizeColumnsToFit && this.gridApi) {
858
+ this.gridApi.sizeColumnsToFit();
859
+ }
860
+ }
861
+ /**
862
+ * Calculates the total width of all columns
863
+ * @private
864
+ */
865
+ calculateTotalColumnWidth() {
866
+ if (!this.columnApi) {
867
+ return 0;
868
+ }
869
+ const allColumns = this.columnApi.getAllGridColumns();
870
+ const currentColumnCount = allColumns.length;
871
+ // Check if cache is still valid (same number of columns)
872
+ if (this.cachedTotalColumnWidth !== null && this.columnCount === currentColumnCount) {
873
+ return this.cachedTotalColumnWidth;
874
+ }
875
+ // Calculate and cache the total width
876
+ this.cachedTotalColumnWidth = allColumns.reduce((sum, col) => sum + (col.getActualWidth() || 0), 0);
877
+ this.columnCount = currentColumnCount;
878
+ return this.cachedTotalColumnWidth;
879
+ }
880
+ /**
881
+ * Invalidates the cached column width calculation
882
+ * @private
883
+ * @remarks This method is called automatically when column changes occur (resize, move, pin, etc.)
884
+ * to ensure the cached width calculation remains accurate.
885
+ */
886
+ invalidateColumnWidthCache() {
887
+ this.cachedTotalColumnWidth = null;
888
+ this.columnCount = 0;
889
+ }
890
+ /**
891
+ * Gets the available grid width with fallbacks
892
+ * @private
893
+ */
894
+ getGridWidth() {
895
+ const gridElement = this;
896
+ let gridWidth = (gridElement === null || gridElement === void 0 ? void 0 : gridElement.clientWidth) || 0;
897
+ if (gridWidth === 0 && this.gridSlot) {
898
+ gridWidth = this.gridSlot.clientWidth || 0;
899
+ }
900
+ if (gridWidth === 0) {
901
+ gridWidth = this.clientWidth || 0;
902
+ }
903
+ return gridWidth;
904
+ }
760
905
  get observedAttributes() {
761
906
  // allow properties to be supplied either lowercased or kebab-cased
762
907
  // this allows the user to either supply (for example) enableSorting or enabled-sorting
@@ -831,6 +976,12 @@ __decorate([
831
976
  __decorate([
832
977
  attr({ mode: 'boolean', attribute: 'grid-autosizing' })
833
978
  ], GridPro.prototype, "gridAutosizingEnabled", void 0);
979
+ __decorate([
980
+ attr({ mode: 'boolean', attribute: 'size-columns-to-content' })
981
+ ], GridPro.prototype, "sizeColumnsToContent", void 0);
982
+ __decorate([
983
+ attr({ mode: 'boolean', attribute: 'size-columns-to-fit' })
984
+ ], GridPro.prototype, "sizeColumnsToFit", void 0);
834
985
  __decorate([
835
986
  attr({ attribute: 'add-index' })
836
987
  ], GridPro.prototype, "addIndex", void 0);
@@ -858,6 +1009,9 @@ __decorate([
858
1009
  __decorate([
859
1010
  attr({ attribute: 'persist-filter-model-key' })
860
1011
  ], GridPro.prototype, "persistFilterModelKey", void 0);
1012
+ __decorate([
1013
+ attr({ attribute: 'default-column-config' })
1014
+ ], GridPro.prototype, "defaultColumnConfig", void 0);
861
1015
  __decorate([
862
1016
  attr({ attribute: 'header-case-type' })
863
1017
  ], GridPro.prototype, "headerCaseType", void 0);
@@ -28,6 +28,11 @@ export class KVStorageStatePersistence {
28
28
  ]);
29
29
  });
30
30
  }
31
+ deleteColumnState(persistColumnStateKey) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ this.kvStorage.delete([persistColumnStateKey]);
34
+ });
35
+ }
31
36
  migrateLocalStorageToKVStorage(persistColumnStateKey) {
32
37
  return __awaiter(this, void 0, void 0, function* () {
33
38
  var _a;
@@ -24,6 +24,13 @@ export class LocalStorageStatePersistence {
24
24
  this.session.setLocalStorageItem('gridOptions', JSON.stringify(existingOptions));
25
25
  });
26
26
  }
27
+ deleteColumnState(persistColumnStateKey) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const existingOptions = JSON.parse(this.session.getLocalStorageItem('gridOptions') || '{}');
30
+ delete existingOptions[persistColumnStateKey];
31
+ this.session.setLocalStorageItem('gridOptions', JSON.stringify(existingOptions));
32
+ });
33
+ }
27
34
  getFilterModel(persistFilterModelKey) {
28
35
  return __awaiter(this, void 0, void 0, function* () {
29
36
  const localStorageGridOptions = this.session.getLocalStorageItem('gridOptions');
@@ -1,3 +1,34 @@
1
+ /**
2
+ * Converts a ColDef to a ColumnState
3
+ * @param colDef - The column definition to convert
4
+ * @returns The corresponding ColumnState
5
+ * @public
6
+ */
7
+ export function convertColDefToColumnState(colDef) {
8
+ return {
9
+ colId: colDef.field || colDef.colId || '',
10
+ hide: colDef.hide || false,
11
+ width: colDef.width || null,
12
+ pinned: colDef.pinned || null,
13
+ sort: colDef.sort || null,
14
+ sortIndex: colDef.sortIndex || null,
15
+ aggFunc: colDef.aggFunc || null,
16
+ rowGroup: colDef.rowGroup || false,
17
+ rowGroupIndex: colDef.rowGroupIndex || null,
18
+ pivot: colDef.pivot || false,
19
+ pivotIndex: colDef.pivotIndex || null,
20
+ flex: colDef.flex || null,
21
+ };
22
+ }
23
+ /**
24
+ * Converts an array of ColDef to an array of ColumnState
25
+ * @param colDefs - The column definitions to convert
26
+ * @returns The corresponding ColumnState array
27
+ * @public
28
+ */
29
+ export function convertColDefsToColumnStates(colDefs) {
30
+ return colDefs.map(convertColDefToColumnState);
31
+ }
1
32
  /**
2
33
  * Merges two arrays, one of `ColDef` and one of `ColumnState`, and deduplicates them.
3
34
  * @remarks ColDef uses `field` and ColumnState uses `colId` to identify columns.